You are viewing a single comment's thread. Return to all comments →
in JavaScript:
function diagonalDifference(arr) { const n = arr.length; let i = 0; let j = 0; let k = n - 1; let leftDiag = 0; let rightDiag = 0; while (i < n && j < n) { leftDiag += arr[i][j]; rightDiag += arr[i][k]; i++; j++; k--; } return Math.abs(leftDiag - rightDiag); }
Seems like cookies are disabled on this browser, please enable them to open this website
Diagonal Difference
You are viewing a single comment's thread. Return to all comments →
in JavaScript: