Quant Memo
Coding/●●●●●

Return a uniformly random index of the maximum in a stream

Values arrive one at a time and you may read them only once. You want the position of the maximum value, but several positions may tie for that maximum.

Return a uniformly random index among all positions holding the maximum value, in one pass with O(1)O(1) memory. Always returning the first (or last) maximum would bias the choice.

Your answer

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

More Coding questions