Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Naman Jindal
Easy solution + less code

Naman Jindal

Jun 29, 2024

diagonalSum(mat) { let totalSum = 0; // Initialize the total sum let n = mat.length; // ToDo: Write Your Code Here.//[[5]] for(let i = 0; i < n ; i++){ if(i !== n-i-1){ totalSum+=(mat[i][i] + mat[i][n-1-i]) }else{ totalSum+=mat[i][i] } } return totalSum; // Return the calculated total sum }

1

0

Comments
Comments

On this page