• + 0 comments

    Python 3:

    from collections import Counter

    counter = Counter(arr) num_pairs = 0

    for i in arr: if i - k in counter: num_pairs += 1 # Note: integers in arr are distinct

    return num_pairs