You are viewing a single comment's thread. Return to all comments →
O(n+k)
def divisibleSumPairs(n, k, ar): from collections import Counter modulo_count = Counter(num % k for num in ar) count = 0 for i in range(k): j=-i % k num1 = modulo_count.get(i, 0) num2 = modulo_count.get(j, 0) if i>j or num1==0 or num2==0: continue if i==j: count+= num1*(num1-1)//2 else: count+=num1*num2 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 →
O(n+k)