You are viewing a single comment's thread. Return to all comments →
In C# 100%
public static int divisibleSumPairs(int n, int k, List<int> ar) { int count = 0; int[] remainders = new int[k]; for (int i = 0; i < n; i++) { int currentRemainder = ar[i] % k; if (currentRemainder < 0) currentRemainder += k; int complement = (k - currentRemainder) % k; count += remainders[complement]; remainders[currentRemainder]++; } return count; }
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 →
In C# 100%