Quant Memo
Coding/●●●●●

Count order pairs summing to a target size

You have a list of order sizes and a target notional T. Count how many unordered pairs of positions (i, j) with i < j satisfy sizes[i] + sizes[j] == T. Repeated sizes count as distinct positions.

sizes = [1, 1, 2, 3, 3], T = 4
-> 4            # each of the two 1s pairs with each of the two 3s

Return the number of such pairs. Aim for O(nlogn)O(n \log n) dominated by the sort.

Your answer

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

More Coding questions