You are viewing a single comment's thread. Return to all comments →
Js/Ts
function diagonalDifference(arr: number[][]): number { let matrixSize = arr.length; let sumFirstDiag = 0; let sumSecondDiag = 0; for (let rows = 0, cols = matrixSize-1; rows < matrixSize; rows ++, cols--){ sumFirstDiag += arr[rows][rows]; sumSecondDiag += arr[rows][cols]; } const result = Math.abs(sumFirstDiag - sumSecondDiag); return result; }
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 →
Js/Ts