You are viewing a single comment's thread. Return to all 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
Seems like cookies are disabled on this browser, please enable them to open this website
Pairs
You are viewing a single comment's thread. Return to all 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