Created
October 1, 2021 07:20
-
-
Save themonster2015/917ecba580886e58f5bdf2cf8dbdd3ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://www.hackerrank.com/challenges/diagonal-difference/problem?isFullScreen=true | |
function diagonalDifference(arr) { | |
let sum1 = 0, sum2 = 0 | |
for(let i = 0; i < arr.length; i++ ){ | |
sum1 += arr[i][i] | |
let j = arr.length - 1 - i | |
sum2 += arr[i][j] | |
//console.log(arr[i][j]) | |
} | |
return Math.abs(sum1 - sum2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment