Skip to content
Onsite

Diagonal Difference

EasyP3Coding

For a square matrix, compute the sum of the main diagonal (top-left to bottom-right) and the sum of the secondary diagonal (top-right to bottom-left). Return the absolute difference between the two sums.

Example 1

Input
matrix = [[11,2,4],[4,5,6],[10,8,-12]]
Output
15

Example 2

Input
matrix = [[1,2],[3,4]]
Output
0

Example 3

Input
matrix = [[5]]
Output
0

Constraints

  • 1 <= N <= 100
  • -100 <= matrix[i][j] <= 100

Hints

Run checks the 3 visible tests, Submit all 10.