FastPrepExpected Flips for k Heads in a Row
Problems/Expected Flips for k Heads in a Row

Expected Flips for k Heads in a Row

Jane Street logoJane Street● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in two Jane Street trading desk operations reports posted in 2024. A London report that lists four interview rounds, one of them a phone round of brain teasers, asked for the expected number of flips to get a head; it does not say which round the question came from. A U.S. report that lists four interview rounds, one of them with math questions, asked for the expected number of flips to get three heads in a row; it does not say which round the question came from. Neither report says the coin is fair.

Our function takes the run length k, and the fair coin is our assumption. The limit on k and the example with two heads in a row are ours.

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

You flip a fair coin again and again. Each flip is heads or tails with equal chance, independently of the others. You stop as soon as the last k flips were all heads.

Return the expected number of flips you make. The answer is always a whole number.

Function

expectedFlips(k: int) → long

Examples

Example 1

k = 3return = 14

Let E0, E1 and E2 be the expected number of flips still needed when the current run of heads has length 0, 1 and 2. Each flip either extends the run or, on tails, sends you back to a run of 0: E2 = 1 + E0/2, E1 = 1 + E2/2 + E0/2 and E0 = 1 + E1/2 + E0/2. Solving gives E0 = 14.

Example 2

k = 1return = 2

Each flip is heads with chance 1/2, so the first head comes after 2 flips on average.

Example 3

k = 2return = 6

You first need a head, which takes 2 flips on average. One more flip then ends the game half the time; on tails you start again from nothing. So E = 2 + 1 + E/2, which gives E = 6.

Constraints

  • 1 <= k <= 50

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

  • 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
  • Median of Uniform Draws in an IntervalSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) 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

Interview reports that mention this question

  • Jane Street TDO UK and Hong Kong: 22 Experiences (Part 10 of 10)
  • Jane Street TDOE Interviews: 165 Experiences (Part 1 of 10)
  • Jane Street TDOE US Phone Screen: 20 Experiences (Part 6 of 10)

Jane Street interview experiences

  • 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)
All Jane Street interview questionsSee Jane Street hiring insights
Saved
class Solution {
    public long expectedFlips(int k) {
      // Write your code here.
    }
}
Checking account…