You are viewing a single comment's thread. Return to all comments →
def diagonalDifference(arr): primary_diagonal_sum = 0 secondary_diagonal_sum = 0 n = len(arr) for i in range(n): primary_diagonal_sum += arr[i][i] secondary_diagonal_sum += arr[i][n - 1 - i]
return abs(primary_diagonal_sum - secondary_diagonal_sum)
Seems like cookies are disabled on this browser, please enable them to open this website
Diagonal Difference
You are viewing a single comment's thread. Return to all comments →
def diagonalDifference(arr): primary_diagonal_sum = 0 secondary_diagonal_sum = 0 n = len(arr) for i in range(n): primary_diagonal_sum += arr[i][i] secondary_diagonal_sum += arr[i][n - 1 - i]