Coin Race to k: Chance It Ends on Flip m
Updated
Problem statement
You flip a fair coin again and again. Each flip is heads or tails with equal chance, independently of the others. The game stops as soon as heads has come up k times in total or tails has come up k times in total. The flips do not need to be in a row.
Return the probability that the game ends on exactly the m-th flip.
Answers within 10-9 of the correct value are accepted.
Function
endsOnFlip(k: int, m: int) → doubleExamples
Example 1
k = 4m = 5return = 0.25Nobody can reach four of a face in fewer than four flips. The game does not end on flip 4 but ends on flip 5 exactly when the first four flips split three to one, which happens with chance 8/16 = 1/2, and flip 5 then matches the face that has three, with chance 1/2. So the answer is 1/4.
Example 2
k = 2m = 3return = 0.5After two flips the game is still running only if they were one head and one tail, with chance 1/2. Then flip 3 gives some face its second appearance whatever it shows, so the answer is 1/2.
Example 3
k = 4m = 8return = 0.0After seven flips one face has come up at least four times, so the game always ends by flip 7 and never reaches flip 8.
Constraints
1 <= k <= 10001 <= m <= 2000
More Jane Street Phone Screen questions
- Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026
- Tree Selection and VisibilityPHONE SCREEN · Seen Nov 2026
- Load/Store Arithmetic InterpreterPHONE SCREEN · Seen Oct 2026
- Instrument Stack Language JumpsPHONE SCREEN · Seen Oct 2026
- Run a Stack Language InterpreterPHONE SCREEN · Seen Oct 2026
- Positive-Integer Expression EvaluationPHONE SCREEN · Seen Oct 2026
- Add Two Integers Given as StringsPHONE SCREEN · Seen Sep 2026
- Angle Between Clock HandsPHONE SCREEN · Seen Jul 2026
- Route Length From Two CyclistsPHONE SCREEN · Seen Jul 2026
- Sort TradesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- Best Single Reroll for Five DiceSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
- Count Array DerangementsInMobi · PHONE SCREENInMobi interview questions
- Biased Coin: Probability of Exactly h HeadsAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Revolver: Will the Next Shot Fire?Tower Research Capital · PHONE SCREEN
- Probability of Consecutive HeadsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Expected Fake-Name CollisionsMercor · PHONE SCREENMercor interview questions
- Election District Budget Allocation AnalysisIMC Trading · PHONE SCREENIMC Trading interview questions
- Count Clean Attendance LogsRippling · PHONE SCREENRippling interview questions
- Extra Coin Win ProbabilityMicrosoft · PHONE SCREENMicrosoft interview questions
- Count Staircases with Strictly Increasing StepseBay · ONSITE INTERVIEWeBay interview questions
Interview reports that mention this question
Jane Street interview experiences
- Jane Street TDO UK and Hong Kong: 22 Experiences (Part 10 of 10)
- Jane Street TDOE US Final Round: 11 Experiences (Part 5 of 10)
- Jane Street TDO Phone Math Round: 26 Experiences (Part 9 of 10)
- Jane Street TDOE UK Phone Screen: 15 Experiences (Part 4 of 10)
- Jane Street TDO Excel and VBA Test: 23 Experiences (Part 8 of 10)