Tap here to switch tabs
Problem
Submissions

Problem: Matrix Diagonal Sum

Matrix Diagonal Sum asks you to add every value on a square matrix’s primary and secondary diagonals, counting the center cell only once when the diagonals cross.

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

Matrix Diagonal Sum asks you to add every value on a square matrix’s primary and secondary diagonals, counting the center cell only once when the diagonals cross.

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