Quant Memo
Coding/●●●●

Two-sum on a sorted price ladder

You are given an already sorted list of price levels and a target. Two of them should add up to the target exactly.

levels = [1, 3, 4, 5, 7, 11], target = 9
-> (2, 3)          # levels[2] + levels[3] == 4 + 5 == 9

Return the indices of any two distinct entries that sum to the target, or None if none exists. Use O(n)O(n) time and O(1)O(1) extra space.

Show a hint

The list is sorted. If the two ends sum to too much, which end should move, and why can you never need it again?

Your answer

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

More Coding questions