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
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.