/diagonal_difference

Diagonal Difference Code Challenge

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Diagonal Difference

Directions

  1. Fork this.
  2. Clone it.
  3. Make changes, commit, and push.
  4. Open a PR.

Challenge

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