Last active
October 12, 2021 09:52
-
-
Save Stefanacef/5f8864ecd9737b332797f57d8e1e43a5 to your computer and use it in GitHub Desktop.
Solution for "Divisible Sum Pairs" in Hackerrank
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
const ar = [1, 3, 2, 6, 1, 2]; | |
const n = 6; | |
const k = 3; | |
function divisibleSumPairs(n, k, ar) { | |
let count=0; | |
for(let i= 0;i<n;i++){ | |
for(let j=i+1;j<n;j++){ | |
let sum =ar[i]+ar[j]; | |
if(sum%k===0){ | |
count++ | |
} | |
} | |
} | |
return count | |
} | |
console.log(divisibleSumPairs(n, k, ar)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment