Diagonal Difference

  • + 0 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)