Dice-Walk Winning Probability
Updated
Problem statement
Start at position 0 on an infinite one-dimensional grid. While the current position is less than mn, roll a fair k-sided die with faces 1 through k and move forward by the rolled value. Rolls are independent.
Stop immediately when the position is at least mn. Win if that stopping position is at most mx; otherwise lose. Return the exact winning probability as a floating-point value computed analytically, without Monte Carlo sampling.
Function
winningProbability(k: int, mn: int, mx: int) → doubleExamples
Example 1
k = 10mn = 1mx = 6return = 0.6The first roll ends the walk; six of the ten equally likely faces win.
Example 2
k = 2mn = 2mx = 2return = 0.75Rolling 2 immediately wins with probability 1/2. Rolling 1 followed by 1 also wins, adding 1/4.
Example 3
k = 3mn = 0mx = 0return = 1.0The walk starts in its stopping interval, so no roll is made.
Constraints
1 <= k <= 10^4.0 <= mn <= mx <= 10^4.- An answer within absolute error
10^-9is accepted.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- New 21 Game ProbabilityUiPath · PHONE SCREEN
- Maximum Earnings Across WarehousesAmazon · ONSITE INTERVIEW
- Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
- Knight Probability in ChessboardGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Count Staircases with Strictly Increasing StepseBay · ONSITE INTERVIEWeBay interview questions
- Count Divisible Power SumsGoodScore · ONSITE INTERVIEW
- 3D Grid Diagonal Walk ProbabilityApple · PHONE SCREENApple interview questions
- Coin Game From The EndsTekion · PHONE SCREENTekion interview questions
- Highest Die Roll WinsJane Street · PHONE SCREENJane Street interview questions
- Tile a Three-Row Board with DominoesJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions