Tap here to switch tabs
Problem
Submissions

Problem: Matrix Diagonal Sum

med
30 min
Try to solve the Matrix Diagonal Sum problem.

Statement

Given a square matrix mat, calculate and return the sum of all elements lying on its primary diagonal and secondary diagonal.

Elements that belong to both diagonals should only be included once in the total sum.

Constraints:

  • n == mat.length == mat[i].length

  • 1≤1 \le n ≤100\le 100

  • 1≤1 \le mat[i][j] ≤100\le 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Matrix Diagonal Sum

med
30 min
Try to solve the Matrix Diagonal Sum problem.

Statement

Given a square matrix mat, calculate and return the sum of all elements lying on its primary diagonal and secondary diagonal.

Elements that belong to both diagonals should only be included once in the total sum.

Constraints:

  • n == mat.length == mat[i].length

  • 1≤1 \le n ≤100\le 100

  • 1≤1 \le mat[i][j] ≤100\le 100