Problem bank
Problem 75 of 333HardCodingP075
Reservoir sampling
You receive a stream of elements one at a time, and you don't know its length in advance. Using constant memory, select one element so that every element is equally likely to be chosen.
Check your answer and see the solution with a free account
Every problem on Quant Engine is free, with a hint and a full worked solution. Making an account takes 30 seconds and no card. Then you can write and check your answers, see the solutions, and track what you have solved.