The 60-second answer
For one/few draws, build cumulative probabilities and binary-search a uniform sample, giving O(n) preprocessing and O(log n) per draw. For very many draws from a fixed distribution, explain the alias method: O(n) preprocessing and O(1) expected draw time.
Build the answer in this order
For one/few draws, build cumulative probabilities and binary-search a uniform sample, giving O(n) preprocessing and O(log n) per draw.
For very many draws from a fixed distribution, explain the alias method: O(n) preprocessing and O(1) expected draw time.
Handle normalization, zero probabilities, floating-point boundaries, and deterministic seeding in tests.
Choose the method from update frequency versus sample volume rather than automatically using the theoretically fastest draw.
A useful interview mental model
This is the shape of a strong answer—not a script to memorize.
Senior-level signal
- Senior answers discuss dynamic weights, where Fenwick/segment trees can support updates plus O(log n) sampling.
- Mention statistical tests for empirical frequency and reproducibility, not just unit tests of index bounds.
What the interviewer is really testing
Likely follow-up questions
Common weak-answer patterns
- Reciting a definition without mechanism or assumptions.
- Claiming one technique is always better without a data regime.
- Stopping before failure modes, validation, or deployment implications.