Reservoir Sampling

medium
Unit 19 · Selection0/3 to milestone

Pick k items uniformly at random from a stream too big to store, or whose length you don't know in advance, such as sampling log lines for review.

Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Reservoir Sampling · TechGradify