• + 0 comments
    def pairs(k, arr):
        m = {}
        pairs = 0
        for num in arr:
            complement = num + k
            if complement in m:
                pairs += m[complement]
            else:
                m[complement] = m.get(complement, 0) + 1
        
        for num in arr:
            if num in m:
                pairs += m[num]
        return pairs