Optimal Stopping for Die Rolls That Bust on Perfect Squares
Company: Jane Street
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
You repeatedly roll a fair six-sided die and keep a running cumulative sum $S$ of all the values rolled so far (starting from $S = 0$ before the first roll).
- After any roll, you may choose to **stop** and walk away with a payoff equal to the current sum $S$.
- However, if at any point the cumulative sum $S$ lands exactly on a positive perfect square ($1, 4, 9, 16, 25, \dots$), you immediately **lose everything**: the game ends with payoff $0$.
- If you keep rolling and have not busted, the game continues indefinitely — there is no limit on the number of rolls.
Determine the optimal strategy: for which values of the running sum should you keep rolling, and at which values should you stop and take the money? Justify why the strategy is optimal, and compute the expected payoff of the game under optimal play, starting from a sum of $0$.