Proving Reservoir Sampling Picks Every Story Uniformly

Last updated: November 29, 2026

Quick Overview

Integrity reviewers want k Stories sampled uniformly at random from a stream whose length n is unknown in advance, using O(k) memory. Describe reservoir sampling and prove that every item ends up in the sample with probability k/n.

Meta
Statistics & Math
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Statistics & Math
Medium

0

0

0 solved


Integrity reviewers want k Stories sampled uniformly at random from a stream whose length n is unknown in advance, using O(k) memory. Describe reservoir sampling and prove that every item ends up in the sample with probability k/n.

Meta streams huge volumes of content into review and labeling queues, and uniform samples are needed for prevalence measurement. Interviewers ask this to test whether a candidate can both implement the algorithm and prove its correctness with a short induction on probabilities.

What the Interviewer Expects
  • Keep the first k items, then replace a random slot with probability k/i for item i
  • Prove by induction that each item is in the reservoir with probability k/i after i items
  • Show the survival product telescopes
  • Provide working code and an empirical check
  • Mention weighted variants for importance sampling
Key Topics to Cover
Reservoir sampling
Induction
Telescoping products
Streaming algorithms
How to Approach This
  1. Define your hypotheses (H0 and H1) clearly before performing any test.
  2. Calculate required sample size BEFORE running an experiment, using power analysis.
  3. Remember the Central Limit Theorem: sample means become approximately normal with large n.
  4. Watch for Simpson's paradox. Always segment data by key dimensions.
  5. Distinguish between statistical significance and practical significance.
Possible Follow-up Questions
  • How would you sample with weights proportional to views?
  • How do you parallelize across many stream partitions?
  • What changes if items can be deleted from the stream?
  • How would you check uniformity empirically?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Browse Statistics Questions
Sample Answer
Clarify

We see items one at a time, do not know nn, can store only kk items, and want each kk-subset (or at least each item) to be in the final sample with the right probability: k/nk/n per item....

Approach

Algorithm R: store the first kk items. For item i>ki > k, draw jj uniform in {1,…,i}\{1, \dots, i\}; if j≤kj \le k, replace slot jj with item ii. So item ii enters with probability k/ik/i and, if it ente...


Submit Your Answer
Markdown supported