diagonal difference hackerrank solution in python

Solutions on MaxInterview for diagonal difference hackerrank solution in python by the best coders in the world

showing results for - "diagonal difference hackerrank solution in python"
Tim
10 Jan 2018
1prim =0
2    sec=0
3    length = len(arr[0])
4    for count in range(length):
5        prim += arr[count][count]
6        sec += arr[count][(length-count-1)]
7    return abs(prim-sec)
8    
Evelin
15 May 2019
1def diagonalDifference(arr):
2    # Write your code here
3    d1 =0
4    d2=0
5    for i in range(len(arr[0])):
6        d1 += arr[i][i]
7        d2 += arr[i][(len(arr[0])-i-1)]
8    return abs(d1-d2)
Blanche
10 Jan 2020
1def diagonalDifference(arr):
2    # Write your code here
3    d1 = sum([arr[x][x] for x in range(len(arr))])
4    d2 = sum([arr[x][n - 1 - x] for x in range(len(arr))])
5    return(abs(d1 - d2))