We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Oh nice, I did this too in Javascript! I was afraid it wouldn't work because the pattern "seemed" to be that the x/y coordinates added up to be 1 less than N.
var backSlash = 0;
var forwardSlash = 0;
for (var i = 0; i < n; i++) {
for (var j = 0; j < n; j++) {
if (i == j) {
backSlash += a[i][j];
}
if (i + j == n-1) {
forwardSlash += a[i][j];
}
}
}
console.log(Math.abs(backSlash - forwardSlash));
Cookie support is required to access HackerRank
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 →
Oh nice, I did this too in Javascript! I was afraid it wouldn't work because the pattern "seemed" to be that the x/y coordinates added up to be 1 less than N.