Quant Memo
Coding/●●●●

Two-sum on a list of trade sizes

You're given an unsorted list of trade sizes and a target block size. Two of your resting child orders should combine to fill the block exactly.

sizes = [2, 7, 11, 15], target = 9
-> (0, 1)          # sizes[0] + sizes[1] == 9

sizes = [3, 3], target = 6
-> (0, 1)

Return the indices of any two distinct entries that sum to the target, or None if no pair exists. Aim for O(n)O(n).

Show a hint

Scanning all pairs is O(n2)O(n^2). As you walk the list once, what single question would let you finish immediately at the current element?

Your answer

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

More Coding questions