You are viewing a single comment's thread. Return to all comments →
You can calculate the sum as you iterate as well.
var sum = 0; for(var i = 0; i<n; i++){ sum += a[i][i]; sum -= a[i][n-i-1]; } console.log(Math.abs(sum));
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 →
You can calculate the sum as you iterate as well.