---
title: You flip a fair coin until you see two heads in a row. What is the expected number of flips? Set it up as a small…
url: https://gurkanozkan.ai/learn/questions/research-expected-waiting-time-010/
markdown: https://gurkanozkan.ai/learn/questions/research-expected-waiting-time-010.md
kind: question
role: Research
stage: Technical
difficulty: Medium
json: https://gurkanozkan.ai/api/learn/questions/research-expected-waiting-time-010.json
robots: noindex
---

# You flip a fair coin until you see two heads in a row. What is the expected number of flips? Set it up as a small Markov chain, solve it, and explain how the method generalises.

Research · Technical · Medium

Theme reported publicly: [Google DeepMind](https://www.algomindset.com/blog/google-deepmind-research-engineer-interview-guide)

## Answer

*Model answer, written in a candidate's voice*

### In short

- States: no progress (S0) and one head (S1).
- First-step equations E0 = 1 + 1/2 E1 + 1/2 E0 and E1 = 1 + 1/2 E0, giving E0 = 6 (E1 = 4).
- Generalises: different patterns have different waiting times (HTH = 10 vs HHT = 8); absorbing chains and the fundamental matrix N = (I-Q)^{-1}.
- Quick simulation check: average flips over many trials lands near 6, consistent with the exact answer.

### In full

Model the process with two transient states: S0 = no progress (start or previous flip was a tail) and S1 = one head in a row, with absorption on the second consecutive head. First-step analysis gives E0 = 1 + 1/2 E1 + 1/2 E0 and E1 = 1 + 1/2 E0 (a head finishes, a tail returns to S0), which solves to E0 = 6 and E1 = 4. The same method generalises to any pattern: build the states as the longest suffix that is also a prefix of the target pattern, write first-step equations, and solve; different patterns genuinely differ, e.g. HTH has expected waiting time 10 while HHT has 8. Equivalently, set up an absorbing Markov chain with transient-state matrix Q and use the fundamental matrix N = (I-Q)^{-1}, with expected absorption times given by N times the all-ones vector. As a quick check, a simulation that repeats the flip-until-HH process many times and averages the flip counts returns a value near 6, consistent with the exact answer.

```calc
E1 = 1 + ½·E0                      (head → done, tail → S0)
E0 = 1 + ½·E1 + ½·E0  →  E0 = 2 + E1
E0 = 2 + (1 + ½·E0)   →  ½·E0 = 3  →  E0 = 6, E1 = 4
```

*Corrected by an independent AI reviewer.*

## What a strong answer covers

- States: "no progress" and "one head".
- First-step equations: E₀ = 1 + ½E₁ + ½E₀ and E₁ = 1 + ½E₀, which give E₀ = 6.
- Generalises: different patterns have different waiting times (HTH vs HHT); absorbing chains; the fundamental matrix.
- Checks the answer with a quick simulation.

## Common mistakes

- Answering 4 by naive reasoning.
- A wrong transition after a tail from the one-head state.
---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
