# Expected Number of Coin Flips to Get k heads OR k tails consecutively?

I’ve figured out the formula for the expected number of coin flips to get k heads in a row for an unfair coin with probability of heads p, but how would one extend this to the question of getting EITHER k consecutive heads or k consecutive tails?

The formula for the heads only case is as follows: E[T_k] = E[T_k-1] + p(1) + (1-p)(E[T_k] +1) This simplifies to E[T_k] = 2E[T_k-1] + 2 or, in functional form, f(k) = 2^(k+1) - 2

I’m very tempted to say that the tails OR heads case is just one half of this, so that f(k) = 2^k - 1.

This works for the k=1 and k=2 cases, but the logic gets too messy for me to manually verify it beyond that.

Get the individual expected values (of k consecutive heads, of k consecutive tails); then take one half of the HARMONIC mean of the two. The rationale is explained in "Informal Introduction to Stochastic Processes with Maple" (Springer). The individual expected values are $$\frac{1-p^k}{qp^k}$$ and $$\frac{1-q^k}{pq^k}$$ respectively (same reference). All of these results are derived via the corresponding probability generating functions, but that would take several pages.