← LinkedIn Interview Insights

LinkedIn·Data Scientist·Technical Phone Screen·Senior

SeniorPrefer not to say
Jul 2026Remote

Summary

LinkedIn data scientist interview that went deep into probability theory, specifically around coin flip stopping times. Not your typical SQL or metrics question, this one felt more like a grad school exam than a product interview.

Questions Asked (3)

Q1

For a fair coin, what is the expected number of flips until you see two consecutive heads? Derive it using a state-based or Markov chain argument.

Algorithms & Data Structures
Author's notes

I set up three states: start, one head seen, done.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Define states based on the current streak of consecutive heads (0, 1, or 2) and set up equations for the expected number of flips from each state. Solve the system of linear equations to find the expected flips from the start state.

Pro tip: After solving, verify the result using an alternative method like martingale or simulation to demonstrate robustness and catch errors.

1. Define States

Identify the relevant states: S0 (no consecutive heads, i.e., last flip was T or no flips), S1 (last flip was H but not two in a row), and S2 (two consecutive heads, absorbing state).

2. Set Up Equations

Let E0, E1, and E2 be the expected additional flips from each state. Write equations: E0 = 1 + 0.5 E0 + 0.5 E1, E1 = 1 + 0.5 E0 + 0.5 E2, and E2 = 0.

3. Solve the System

Substitute E2 = 0 into the equations and solve for E0 and E1. From E1 = 1 + 0.5 E0, and E0 = 1 + 0.5 E0 + 0.5 E1, derive E0 = 6.

4. Verify and Interpret

Check the solution by plugging back or using an alternative method (e.g., simulation or martingale). Interpret the result: on average, it takes 6 flips to see two consecutive heads.

Key Points to Mention

  • Definition of states based on the current streak of heads.
  • Setting up equations using first-step analysis (law of total expectation).
  • Solving the linear system to find the expected value.
  • The absorbing state (two consecutive heads) has expected additional flips of 0.
  • Verification of the result (e.g., via simulation or alternative derivation).
  • The final answer is 6 flips.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Now generalize: if the coin has probability p of heads, what is the expected number of flips to see HH?

Algorithms & Data Structures
Author's notes

Same state setup, just replace 0.5 with p and 0.5 with (1-p).

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Set up a system of equations using states based on the current run of consecutive heads (0, 1, or 2). Solve for the expected number of flips from state 0, then verify with a simpler case (e.g., p=0.5) to ensure correctness.

Pro tip: Always check your general formula against known special cases (like p=0.5 giving 6 flips) to catch algebra mistakes and demonstrate rigor.

1. Define states

Define states based on the current streak of consecutive heads: state 0 (no recent heads), state 1 (one head), state 2 (two heads, absorbing).

2. Set up equations

Let E0, E1, E2 be the expected additional flips from each state. Write equations: E2=0, E1=1 + p*E2 + (1-p)*E0, E0=1 + p*E1 + (1-p)*E0.

3. Solve the system

Solve for E0 in terms of p. From E0 equation: E0 = 1/p + E1. Substitute E1 = 1 + (1-p)E0, then solve to get E0 = (1+p)/p^2.

4. Verify with special cases

Check p=0.5 gives 6, p=1 gives 2, and p→0 gives infinity, confirming the formula's plausibility.

Key Points to Mention

  • Definition of states based on consecutive heads
  • Setting up linear equations for expected values
  • Solving the system algebraically
  • Verification with p=0.5 (expected 6 flips)
  • Edge cases: p=1 (2 flips) and p=0 (infinite)
  • Alternative derivation using Markov chain or martingale

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

For the fair coin case, derive the variance of T, the number of flips until HH appears. Walk through your full reasoning.

Algorithms & Data Structures
Author's notes

This is where I struggled.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the process as a Markov chain with states: 0 (no progress), 1 (last flip was H), 2 (HH achieved). Set up equations for the expected value and second moment of the hitting time T, then compute Var(T) = E[T^2] - (E[T])^2. Alternatively, use the martingale or pattern-matching approach to directly derive the variance.

Pro tip: After deriving the variance, mention that the distribution of T is not geometric and has a longer tail; this shows deeper understanding. Also, be prepared to generalize to other patterns or biased coins.

1. Define states and transitions

Define states: S0 (no progress), S1 (last flip H), S2 (HH achieved). Specify transition probabilities: from S0, H→S1, T→S0; from S1, H→S2, T→S0; S2 is absorbing.

2. Set up equations for expected hitting time

Let E_i be expected flips to reach S2 from state i. Write E_0 = 1 + 0.5 E_0 + 0.5 E_1, E_1 = 1 + 0.5*0 + 0.5 E_0, E_2=0. Solve to get E_0 = 6.

3. Set up equations for second moment

Let M_i = E[T^2 | start in state i]. Use the relation M_i = 1 + sum_j P_ij (2 E_j + M_j) for i≠2, with M_2=0. Write equations for M_0 and M_1.

4. Solve for second moment and variance

Solve the linear system for M_0 and M_1. Then Var(T) = M_0 - (E_0)^2. Compute the final numerical value.

5. Verify and interpret

Check that variance is positive and reasonable. Optionally, compare with simulation or known results. Discuss implications for the distribution of T.

Key Points to Mention

  • Markov chain states and transition probabilities
  • First-step analysis for expected hitting time
  • Equation for second moment using E[T^2] = 1 + sum P_ij (2 E_j + M_j)
  • Solving linear equations to get E[T]=6 and E[T^2]=?
  • Variance formula Var(T) = E[T^2] - (E[T])^2
  • Non-geometric distribution and heavy tail

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.