You are viewing a single comment's thread. Return to all comments →
def divisibleSumPairs(n, k, ar): total_pairs = 0 remainder_count = [0] * k for num in ar: remainder = num % k complement = (k - remainder) % k total_pairs += remainder_count[complement] remainder_count[remainder] += 1 return total_pairs
Time complexity: O(n)
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 →
Python
Time complexity: O(n)