e = 0
ans = []
for a in l1:
    while b < len(l2) and a - l2[b] > dist:
        b += 1
while e < len(l2) and l2[e] - a <= dist:
    e += 1
ans.extend([(a, x) for x in l2[b:e]])
return ans
Given Two Lists of Integers, Find Each Pair Within a Distance of Each Other < O(N^2)