← Questions

Restart strategy that cuts a solver's expected run time

0
OpenAICodingLast asked May 2026

A coding interview question asked in OpenAI's technical screen (coding), last asked May 2026. It tests probability, algorithms and optimization.

A model solves math problems with a randomized solver. Each run either finds a solution after some number of steps or keeps going; the number of steps a run needs is random and long-tailed, and independent between runs. You may stop a run at any point and start a fresh one. Find the restart policy that minimises the expected total number of steps until a solution, first when the run-time distribution is known, then when it is not.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • best_cutoff(pmf: dict[int, float]) -> tuple[int, float] — pmf[x] is the probability that a run needs exactly x steps. Return the cutoff t (restart every run that hasn't finished after t steps) with the smallest expected total steps, and that expectation.
  • schedule(i: int) -> int — for Part 2, the cutoff to use on the i-th run when the distribution is unknown.

Part 1: known distribution

With cutoff t, each run costs min(X, t) and succeeds with probability F(t) = P(X <= t), so the expected total is E[min(X, t)] / F(t).

pmf = {1: 0.5, 100: 0.5}
    no restarts (t = 100): 50.5     t = 1: 1 / 0.5 = 2.0      ->  (1, 2.0)

pmf = {1: 0.1, 3: 0.6, 20: 0.3}
    t = 1: 10.0     t = 3: 2.8 / 0.7 = 4.0     t = 20: 7.9     ->  (3, 4.0)

Part 2: unknown distribution

You know nothing about the distribution. Give a fixed schedule of cutoffs whose expected time is never much worse than the best fixed cutoff for whatever distribution you face, and state how much worse it can be.

Luby-style schedule:  1, 1, 2, 1, 1, 2, 4, 1, 1, 2, 1, 1, 2, 4, 8, ...

Constraints

  • Up to 10^5 support points in pmf; probabilities sum to 1 (or less, with the rest meaning "never finishes").
  • Runs are independent; a restart costs nothing extra unless you choose to model it.

Clarifying questions

  • Is a step count discrete, or is time continuous?
  • Does restarting have a fixed overhead?
  • Is there a probability that a run never finishes?
  • Can runs execute in parallel on several machines?

What a strong answer covers

  • Deriving E[min(X, t)] / F(t): a geometric number of attempts, each failed one costing t.
  • Why the best cutoff is always at a support point, and computing all candidates in one pass with prefix sums: O(n log n) after sorting.
  • Why restarts help only for heavy tails (no gain when the distribution is memoryless, as with a geometric one).
  • The universal schedule: each cutoff value 2^k gets equal total time, giving an expected time within a logarithmic factor of the optimal fixed cutoff for every distribution, and why no universal schedule can do better than that order.
  • Testing by simulation against the closed form.

Follow-ups

  • Restarting costs a fixed c steps. How does the optimal cutoff move?
  • You have k machines running in parallel. What changes?
  • Learn the distribution online from finished and cut-off runs and adapt the cutoff.

Where it's asked

  • OpenAI · Technical screen: coding · Last asked May 202660 min · One problem in three to five growing parts filling the hour, usually in CoderPad; ML roles get a Colab notebook with autocomplete off · No AI assistants or autocomplete; documentation is fine

What it tests

probability · algorithms · optimization

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding