- Fork this.
- Clone it.
- Make changes, commit, and push.
- Open a PR.
Given a square matrix, calculate the absolute difference between the sums of its diagonals.
For example, the square matrix is shown below:
1 2 3
4 5 6
9 8 9
The left-to-right diagonal = 15
. The right to left diagonal = 17
. Their absolute difference is |15 - 17|
or 2
.
Note: The square matrix will always come in the form of a nested array.
Example:
squarematrix = [[2, 3, 4, 5],
[5, 5, 5,10],
[0, 7, 13, 10],
[9, 9, 9, 9]]
diagonal_difference(squarematrix) == 3
Level: Easy
Category: Sequence Processing