Quant Memo
Coding/●●●●●

Does a pair of sizes differ by exactly d

Given a list of order sizes and a non-negative difference d, decide whether some two of them differ by exactly d, that is, whether there exist positions i and j with sizes[j] - sizes[i] == d.

sizes = [1, 5, 3, 8], d = 2
-> True            # 3 and 5 differ by 2 (also 1 and 3)

Return True if such a pair exists, else False. Aim for O(nlogn)O(n \log n).

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions