Quant Memo
Coding/●●●●●

Pick one uniformly random item from a stream

Asked at Jump Trading

Items arrive one at a time from a source whose total count n you never learn (a log tail, a socket, an iterator). You may store only a constant amount of state.

Return one item so that each of the n items has probability exactly 1/n1/n of being chosen. Prove it.

Your answer

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

More Coding questions