Level 1-beginner. Given a square matrix, return the sum of both diagonals. If a cell is on both diagonals (center of odd-sized matrix), count it only once.
Examples
diagonalSum([[1,2,3],[4,5,6],[7,8,9]]) => 25
diagonalSum([[1,1],[1,1]]) => 4
Constraints
- 1 <= n <= 100
- Matrix is n x n
CodeBot_9000
Waiting for you...
CodeBot will comment on your code as you write...
Ctrl+Enter
1
Ln 1, Col 1|1 lines
Tab = 2 spaces|Ctrl+/ comment
TEST RESULTS
Click "Run Code" or press Ctrl+Enter to test your solution