Practice interviews

What should the retry simulation report?

Check the success rate and the mean attempt count for a retry rule.

The question

A simulation runs a fictional task until success or the attempt limit. The interviewer asks for exact results to use as a check.

Opening run
Attempt limit
Stop at the first success or after 3 attempts.
Success chance
Each attempt succeeds with probability 1/4, independently.
Report
Successes per run and mean attempts per run.

“What values should a large set of simulated runs approach?”

A strong answer, step by step

Open each step in turn. This is one strong answer, not the only one.

Step 1: What counts as one run?

What would you do here? Open the move you’d make.

  • Count each stopped run once

    The strong move. Success per run can count at most one success for each run.

  • Count every attempt as a new run

    Tempting, but it misses something. That would make a per-attempt statistic instead.

  • Give each run all three attempts

    Tempting, but it misses something. The stated rule stops a run as soon as it succeeds.

See how a strong candidate says it

“Start at attempt one. End the run at its first success or at the attempt limit. Count the run once.”

What a strong candidate could say

Why it works: The measures use runs as their denominator. A run may use fewer than three attempts.

Step 2: What are the exact values?

What would you do here? Open the move you’d make.

  • 3/4 success and 3 attempts

    Tempting, but it misses something. The three first-success paths are weighted by the earlier failures. Many runs stop early.

  • 1/4 success and 1 attempt

    Tempting, but it misses something. Those values only describe a run with no retries.

  • 37/64 success and 37/16 attempts

    The strong move. These count the all-failure path and the chance each attempt occurs.

See how a strong candidate says it

“Success is 1 − (3/4)³ = 37/64. A run always takes the first attempt. It reaches the second with chance 3/4 and the third with chance 9/16. Mean attempts are 37/16.”

What a strong candidate could say

Why it works: The complement is failing all three attempts. The expected count adds the probability of reaching each attempt.

Step 3: What does the retry change?

Attempt 1 still succeeds with probability 1/4. On attempts 2 and 3, the success chance is 1/2 given that all earlier attempts failed.

What would you do here? Open the move you’d make.

  • 7/8 success and 7/4 attempts

    Tempting, but it misses something. That would apply the 1/2 chance to the first attempt too.

  • 13/16 success and 17/8 attempts

    The strong move. The later chances apply after the first attempt fails.

  • 13/16 success and 37/16 attempts

    Tempting, but it misses something. The new second-attempt success chance also reduces how often the third attempt occurs.

See how a strong candidate says it

“The all-failure chance is (3/4) × (1/2) × (1/2) = 3/16, so success is 13/16. Mean attempts are 1 + 3/4 + 3/8 = 17/8.”

What a strong candidate could say

Why it works: The first failure chance remains 3/4. The later chance applies only to a run that reaches the attempt.

Step 4: How would you check the code?

What would you do here? Open the move you’d make.

  • Test stopping paths and compare both averages

    The strong move. This checks the control flow and the results of repeated runs.

  • Check only that one run ends in success

    Tempting, but it misses something. One successful run tells you neither the average nor whether the limit works.

  • Require every simulation to hit both exact values

    Tempting, but it misses something. Finite samples can differ from the exact values even when the simulator is correct.

See how a strong candidate says it

“I’d test an immediate success, a success on retry and a run that stops at the limit. Then I’d compare both simulated averages with the exact values and allow for sampling error.”

What a strong candidate could say

Why it works: The first three checks exercise the stopping logic. The averages check what it produces across many runs.

The answer, in short

Decision
Check the revised simulation against 13/16 success and 17/8 mean attempts.
Because
The first attempt keeps its old chance. The later chances change both measures.
What would change it
Recompute if the stopping limit or conditional chance changes.

Common traps

  • Mixing run-level and attempt-level success
  • Applying the retry chance to the first attempt

Check your answer

  • When does a run stop?
  • How often does each attempt occur?
  • Which success chance changed?
  • What variation would a finite simulation show?

Last reviewed Nov 11, 2026