You are viewing a single comment's thread. Return to all comments →
O(n) solution in JavaScript
function divisibleSumPairs(n, k, ar) { let pairCount = 0; let remainders = new Array(k).fill(0); for(let i = 0; i < n; i++){ let num = ar[i]; let remainder = num % k; let compliment = (k - remainder)% k; pairCount += remainders[compliment]; remainders[remainder]++; } return pairCount; }
Seems like cookies are disabled on this browser, please enable them to open this website
Divisible Sum Pairs
You are viewing a single comment's thread. Return to all comments →
O(n) solution in JavaScript