Problem

Square matrix n*n in row-major; return main diagonal sum.

Examples

  • matrixDiagonalSum([1, 0, 0, 0, 2, 0, 0, 0, 3], 3) -> 6
Compile and test (Ctrl+Enter)