Expected Rolls Until a Specific Two-Die Pattern Appears

Expectation · Medium · Free problem

You roll a fair six-sided die repeatedly. Let $T$ be the first time the pattern "2 followed immediately by 5" appears in consecutive rolls.

Compute $E[T]$, the expected number of rolls until this pattern first occurs.

Hints

  1. Model your progress toward the pattern as a Markov chain. What states do you need to track how close you are to completing "2, 5"?
  2. You need three states: no progress, last roll was a 2, and pattern complete. Write the transition probabilities -- pay attention to what happens when you roll a 2 while already in the "last roll was 2" state.
  3. Set up the equations $E_0 = 1 + \frac{5}{6}E_0 + \frac{1}{6}E_1$ and $E_1 = 1 + \frac{4}{6}E_0 + \frac{1}{6}E_1$, where $E_0$ and $E_1$ are the expected rolls from each non-absorbing state. Substitute and solve.

Worked Solution

How to Think About It: This is a classic pattern-matching stopping time on a Markov chain. The trick is to identify the minimal set of states that capture your progress toward completing the pattern. At any point in the sequence of rolls, the only thing that matters is: did the most recent roll put you partway through the target pattern? Here, the pattern is just two symbols long (2 then 5), so you only need three states. Once you write down the transition equations, it is a small linear system.

Before diving in, notice that the expected time to roll any specific single outcome on a fair die is 6. If the two-symbol pattern were made of two independent events in sequence (no overlap possible), you might guess the answer is around $6 \times 6 = 36$. That turns out to be exactly right here, but for a subtle reason -- the pattern "2, 5" cannot overlap with itself (a 5 is never a 2), so there is no wasted partial progress.

Quick Estimate: If you just needed to see a 2, you would wait on average 6 rolls. Once you see a 2, you need the very next roll to be a 5, which happens with probability

/6$. But if it fails, you might or might not have rolled another 2 (prob
/6$ of staying in the "just saw a 2" state vs. $4/6$ of resetting completely). Rough reasoning: from the "just saw a 2" state, you have a
/6$ chance of finishing on each subsequent roll, but a $4/6$ chance of losing all progress, which is expensive. This suggests the wait from the "just saw 2" state is considerably more than 6. A quick guess: the total should be around 36.

Approach: Define a three-state Markov chain and solve the resulting system of linear equations for the expected hitting time.

Formal Solution:

Define three states based on progress toward the pattern "2, 5":

  • State 0: No useful progress (start state, or last roll was not a 2).
  • State 1: The last roll was a 2 (one symbol of progress).
  • State 2: Pattern complete (absorbing) -- the last two rolls were 2 then 5.

Transitions from State 0 (roll the die): - Roll a 2 (prob

/6$): move to State 1. - Roll anything else (prob $5/6$): stay in State 0.

Transitions from State 1 (roll the die): - Roll a 5 (prob

/6$): move to State 2. Done. - Roll a 2 (prob
/6$): stay in State 1 (the new 2 keeps your progress alive). - Roll anything else (prob $4/6$): back to State 0.

Let $E_0$ and $E_1$ be the expected number of additional rolls to reach State 2 from States 0 and 1, respectively.

From State 0:

$E_0 = 1 + \frac{5}{6} E_0 + \frac{1}{6} E_1$

From State 1:

$E_1 = 1 + \frac{4}{6} E_0 + \frac{1}{6} E_1$

Solve the first equation:

$E_0 - \frac{5}{6} E_0 = 1 + \frac{1}{6} E_1 \implies \frac{1}{6} E_0 = 1 + \frac{1}{6} E_1 \implies E_0 = 6 + E_1$

Substitute into the second equation:

$E_1 = 1 + \frac{4}{6}(6 + E_1) + \frac{1}{6} E_1 = 1 + 4 + \frac{4}{6} E_1 + \frac{1}{6} E_1 = 5 + \frac{5}{6} E_1$

$\frac{1}{6} E_1 = 5 \implies E_1 = 30$

$E_0 = 6 + 30 = 36$

Answer: $E[T] = 36$.

Note: This equals $6 \times 6 = 36$, the product of the expected waiting times for each symbol individually. This is not a coincidence -- it holds for any two-symbol pattern on a fair die where the pattern cannot overlap with itself (i.e., the second symbol differs from the first). For patterns that can overlap (like "2, 2"), the expected time is longer ($36 + 6 = 42$) because a failed completion can leave you with partial progress that "restarts the clock" at a different rate.

Intuition

The core idea here is that any sequential pattern-matching problem on i.i.d. trials can be reduced to a first-passage time on a small Markov chain, where the states represent how much of the target pattern you have built so far. The number of states equals the pattern length plus one (for the "no progress" state). This framework generalizes cleanly: for a length-$k$ pattern on a die, you get $k+1$ states and $k$ linear equations to solve.

The subtlety that separates easy and hard pattern-waiting problems is overlap. When the target pattern can overlap with itself (like "2, 2" -- if you fail by rolling a 2, that 2 is also progress toward the next attempt), partial completions carry over and inflate the expected time. When the pattern cannot overlap with itself (like "2, 5" -- a 5 can never start a new "2, 5" sequence), the problem decomposes more cleanly. In competitive interview settings, this distinction is the thing that separates a good answer from a great one. It also connects to the Conway leading number technique for comparing pattern-race problems, which is a favorite topic in quant interviews.

Open the full interactive solver →