We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Divisible Sum Pairs
Divisible Sum Pairs
Sort by
recency
|
2461 Discussions
|
Please Login in order to post a comment
def divisibleSumPairs(n, k, ar): freq = [0] * k count = 0
My solution in python:
def divisibleSumPairs(n, k, arr):
JAVA Solution
public static int divisibleSumPairs(int n, int k, List ar) {
C# var remainderCounts = new int[k]; var count = 0;
foreach (var num in ar) { var remainder = num % k; var complement = (k - remainder) % k; count += remainderCounts[complement]; remainderCounts[remainder]++; }
return count;
Do not need the n in the function and using itertools to get all unique pairs: