Skip to content

Latest commit

 

History

History
13 lines (11 loc) · 499 Bytes

101-find-sum-of-top-left-to-bottom-right-diagonals.md

File metadata and controls

13 lines (11 loc) · 499 Bytes

Problem:

Given a square matrix (i.e. an array of subarrays), find the sum of values from the first value of the first array, the second value of the second array, the third value of the third array, and so on...

Examples

array = [[1, 2],
         [3, 4]]

diagonal sum: 1 + 4 = 5

array = [[5, 9, 1, 0],
[8, 7, 2, 3],
[1, 4, 1, 9],
[2, 3, 8, 2]]

diagonal sum: 5 + 7 + 1 + 2 = 15

Solution