Given a square matrix `mat`, return the sum of its two diagonals: every cell on the primary diagonal (top-left to bottom-right) plus every cell on the secondary diagonal (top-right to bottom-left) that is not already on the primary one.
Given a square matrix mat, return the sum of its two diagonals: every cell on the primary diagonal (top-left to bottom-right) plus every cell on the secondary diagonal (top-right to bottom-left) that is not already on the primary one.
Example 1:
Input: {"mat":[[1,2,3],[4,5,6],[7,8,9]]}
Output: 25
Constraints:
n==mat.length==mat[i].length
1≤n≤100
1≤mat[i][j]≤100
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"mat":[[1,2,3],[4,5,6],[7,8,9]]}
total starts at 0. Row i touches the primary diagonal at column i and the secondary diagonal at column 3-1-i.