FastPrepChance a Die Game Balance Reaches Zero
Problems/Chance a Die Game Balance Reaches Zero

Chance a Die Game Balance Reaches Zero

Optiver logoOptiver● MediumFULLTIMEOA

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2026 report on an Optiver full-time quant research OA notes that time ran short, then gives a list of 17 probability questions to practice; the die-roll item on that list is the basis of this problem.

In it, the balance starts at 12 and a six-sided die with equal chances for each face is rolled eight times. An even result is added to the balance and an odd result is taken off. The item is about how often the balance would drop to 0 or less at some point. The post does not include an answer.

Our choices: the starting balance, the number of rolls and the face count are inputs (start up to 10^9, up to 100 rolls, 2 to 20 faces; the report uses 12, 8 and 6). We check the balance after every roll, including the final one. A balance of exactly 0 counts, which the report also says. Outputs are decimals; an answer counts as right if it is off from the exact value by at most 10^-9. Example 1 matches the report; the limits and the other examples were picked by us.

Our version is about 90% the same as the reported question.

A game starts with a balance of start. A fair die with faces faces, labeled 1 to faces, is rolled rolls times. On each roll every face is equally likely, and the rolls are independent of each other.

After each roll, the face shown changes the balance: even faces raise it by the face value, odd faces lower it by the face value. The balance is looked at after every roll, including the final one. Return the chance that at least once it is 0 or less. A balance of exactly 0 counts. Once that has happened, the rolls that follow do not change the outcome.

Function

ruinProbability(start: int, rolls: int, faces: int) → double

Examples

Example 1

start = 12rolls = 8faces = 6return = 0.13720755220240816

As a fraction this is 28807/209952: 230,456 of the 1,679,616 equally likely sequences of eight rolls bring the balance to 0 or below after one of the rolls.

Example 2

start = 3rolls = 2faces = 4return = 0.3125

Faces 2 and 4 add, faces 1 and 3 subtract. A first roll of 3 leaves exactly 0, which counts as ruin: chance 1/4. After a first roll of 1 the balance is 2, and a 3 on the second roll makes it -1: chance 1/4 of 1/4 = 1/16. A first roll of 2 or 4 leaves 5 or 7, more than the last roll can take away. The total is 1/4 + 1/16 = 5/16.

Example 3

start = 15rolls = 3faces = 6return = 0.004629629629629629

One roll takes away at most 5, so only three 5s in a row reach 0, and they leave exactly 0. That has chance 1/216. Starting from 16, the answer would be 0.

Constraints

  • 1 <= start <= 10^9
  • 1 <= rolls <= 100
  • 2 <= faces <= 20
  • The checker accepts an answer when |output - exact| <= 10^-9.

More Optiver Online Assessment questions

  • Chance a Hand of Cards Multiplies to More Than a ThresholdOA · Seen Dec 2026
  • Chance a Sum of Random Draws Has a Given Number of DigitsOA · Seen Dec 2026
  • Expected Draws to Remove All Green CountersOA · Seen Dec 2026
  • Expected Profit of a Doubling Betting SystemOA · Seen Dec 2026
  • Expected Steps Until a Random Walk Gets Far From ZeroOA · Seen Dec 2026
  • Rolling Until One Face's Own Total Passes a ThresholdOA · Seen Dec 2026
  • Two Ranked Teams Meeting in a Random BracketOA · Seen Dec 2026
  • Overheat Prevention ControllerOA · Seen Nov 2026
  • Power Cell BankOA · Seen Nov 2026
  • Count Straight-Line Word Occurrences in a GridOA · Seen Sep 2026

Similar questions at other companies

  • Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
  • Count Lucky TicketsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
  • Jump Game with Prime-Step RuleUber · OAUber interview questions
  • Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
  • Unique Paths Through a GridPeopleStrong · OAPeopleStrong interview questions
  • Get Minimum OperationsJP Morgan Chase · OAJP Morgan Chase interview questions
  • Jump Game with Prime-3 StepsAgoda · OAAgoda interview questions
  • Find Encrypted NumberAmazon · OA
  • Prime StringSnowflake · OASnowflake interview questions

Optiver interview experiences

  • Optiver SWE Intern OA: CPU Temperature Simulation: 1 Experience
  • Optiver Trading Intern Market-Making Games: 1 Experience
  • Optiver Quant Trader Intern Technical Interview: 1 Experience
  • Optiver SWE Intern System Design Interview: 15 Experiences
All Optiver interview questionsSee Optiver hiring insights
Saved
class Solution {
    public double ruinProbability(int start, int rolls, int faces) {
        // Write your code here.
    }
}
Checking account…