Skip to content

Instantly share code, notes, and snippets.

@Stefanacef
Last active October 12, 2021 09:52
Show Gist options
  • Save Stefanacef/5f8864ecd9737b332797f57d8e1e43a5 to your computer and use it in GitHub Desktop.
Save Stefanacef/5f8864ecd9737b332797f57d8e1e43a5 to your computer and use it in GitHub Desktop.
Solution for "Divisible Sum Pairs" in Hackerrank
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