The interview problem

Practice prompt

Sample from an unnormalized density using a proposal and a dominating envelope.

Original practice, not a reported company interview. Scenarios and numbers are illustrative. Interview date: not applicable. Sources retrieved October 1, 2026.

1. Scope and worked approach

Choose proposal q and constant M with target kernel g(x)≤Mq(x) everywhere. Draw X~q and U~Uniform(0,1); accept when U≤g(X)/(Mq(X)). Accepted samples follow normalized g. The envelope must hold outside the observed sample region too.

2. Trace the design or derivation

Proposal draw
  → envelope ratio
  → uniform accept/reject
  → accepted sample

Rejected proposals are part of the algorithm, not missing data to impute. If a runtime limit stops collection early, report the actual number of accepted samples and uncertainty. Do not silently force acceptance to meet a batch-size deadline.

3. Calculate the example

For normalized target p(x)=2x on [0,1], uniform q and M=2, accept when U≤x. Acceptance probability is 1/2, so two proposals are needed per accepted sample on average.

4. Failure cases and trade-offs

Underestimating M biases the result; clipping an invalid acceptance ratio does not repair it. Heavy tails can make a convenient-looking proposal unusable.

5. Validation, follow-ups and self-review

Check the accepted empirical CDF and the analytic envelope. Follow-up: what changes in high dimension? Self-review: distinguish proposal efficiency from correctness.

Sources and related practice

Technical reference: www.robots.ox.ac.uk — Acceptance-rejection sampling; triangular-density example is original.

Source publication/update: 2015 lecture material. Retrieved October 1, 2026. The workflow, calculations and review exercises are original; this reference is not evidence that a company asked this question.

Continue with Diagnose high-variance importance-weighted estimates; Estimate expectations with Monte Carlo.

Continue your preparation

Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.