Best of n or Win by L
Updated
Problem statement
You play a match of games against one opponent. You win each game with probability p percent and lose it otherwise; games are independent and there are no draws. You may pick one of two formats:
- Best of
n: play until one player has won(n + 1)/2games. - Lead by
L: play until one player has wonLmore games than the other.
Return the probability that you win the best-of-n match minus the probability that you win the lead-by-L match.
Your answer is accepted if its absolute error or its relative error is at most 10^-9.
Function
formatAdvantage(p: int, n: int, L: int) → doubleExamples
Example 1
p = 60n = 3L = 2return = -0.044307692307692305This is the interview case. Best of three: you win the first two games (0.36), or split them and win the third (2 × 0.6 × 0.4 × 0.6 = 0.288), so 0.648 in all.
Lead by two: look at the games in pairs. A pair you sweep (0.36) wins, a pair you lose twice (0.16) loses, and a split pair (0.48) puts the score back to even. So you win with chance 0.36 / (0.36 + 0.16) = 9/13 ≈ 0.6923. The answer is 0.648 - 9/13 = -72/1625 ≈ -0.0443: lead by two is better.
Example 2
p = 60n = 1L = 1return = 0.0Best of one and lead by one are both a single game, so both chances are 0.6 and the answer is 0.
Example 3
p = 40n = 3L = 2return = 0.044307692307692305Now you are the weaker player. Best of three gives 0.16 + 2 × 0.4 × 0.6 × 0.4 = 0.352 and lead by two gives 0.16 / 0.52 = 4/13 ≈ 0.3077. The answer is +72/1625 ≈ 0.0443. For these two formats, the shorter match gives the weaker player the better chance.
Constraints
1 <= p <= 991 <= n <= 999nis odd.1 <= L <= 100
More Susquehanna International Group (SIG) Phone Screen questions
- Dice Sum That Is a Multiple of mPHONE SCREEN · Seen Nov 2026
- Find Median from Data StreamPHONE SCREEN · Seen Nov 2026
- Painting Arcs to Nearest Neighbors on a CirclePHONE SCREEN · Seen Sep 2026
- Filter Movies by Inclusive Year RangePHONE SCREEN · Seen Jul 2026
- Best Single Reroll for Five DicePHONE SCREEN · Seen Feb 2026
- Catching the Bus to the MoviePHONE SCREEN · Seen Jan 2026
- Two Dice Summing to a TargetPHONE SCREEN · Seen Jan 2026
- Median of Uniform Draws in an IntervalPHONE SCREEN · Seen Oct 2025
- One Number Is the Average of the Other TwoPHONE SCREEN · Seen Jun 2025
- Which Coin Pattern Shows Up FirstPHONE SCREEN · Seen May 2025
Similar questions at other companies
- Dice-Walk Winning ProbabilityGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- 3D Grid Diagonal Walk ProbabilityApple · PHONE SCREENApple interview questions
- Coin Game From The EndsTekion · PHONE SCREENTekion interview questions
- Starting Value with the Longest Collatz ChainZipRecruiter · PHONE SCREENZipRecruiter interview questions
- Count Array DerangementsInMobi · PHONE SCREENInMobi interview questions
- Maximum-Product Subarray with an Empty ChoiceAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Probability of Consecutive HeadsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Count Staircase WaysGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- New 21 Game ProbabilityUiPath · PHONE SCREEN
- Count Stepping Numbers In RangeAmazon · PHONE SCREEN