TITLE: Expected number of ﬂips needed that at least two heads and one tail have been ﬂipped
QUESTION [5 upvotes]: The original question is shown below (References from the book of Introduction to Probability Models Tenth Edition):

A coin, having probability $p$ of landing heads, is continually ﬂipped until at least one head and one tail have been ﬂipped.
(a) Find the expected number of ﬂips needed.
(d) Repeat part (a) in the case where ﬂipping is continued until a total of at least two heads and one tail have been ﬂipped.

I solve the question (a), but I am not sure my answer for question (d).
My answer is shown:
Let $N$ is the number of flips at least two head and one tail.
$$
\begin{align*}
E[N] &= E[E[N|Y]]\\ &= E[N|HH]P(H)P(H) + E[N|HT]P(H)P(T) + E[N|TH]P(T)P(H)
\end{align*}
$$
$E[N|HH]$ means the first two are heads until a tail appeared;
$E[N|HT]$ means the first two are head and tail until a head appeared;
$E[N|TH]$ means the first two are head and tail a head appeared;
Let $E[T] = 1/q = 1/1-p$, $E[H] = 1/p$
Then, $E[N] = (2+1/q)pp + (2+1/p)p(1-p) + (2+1/p)p(1-p)$ ←Ans.
I am not sure whether I am right? Thanks a lot.

REPLY [1 votes]: Let $p$ be the probability of heads $(0\lt p\lt1)$ and $q=1-p$ the probability of tails.
Define random variables $W,X,Y,Z$ as follows: $W$ is the number of flips until you have flipped at least two heads and one tail; the second head comes on the $X^\text{th}$ flip; the first tail comes on the $Y^\text{th}$ flip; and $Z=\min(X,Y)$. Then $W=\max(X,Y)=X+Y-\min(X,Y)=X+Y-Z$, so
$$E[W]=E[X+Y-Z]=E[X]+E[Y]-E[Z]=\frac2p+\frac1q-(1+p)$$$$=\frac2p+\frac1q-(2p+q)=2\left(\frac1p-p\right)+\left(\frac1q-q\right)=\frac2p+\frac{p^2}q.$$
More generally, if $W_{m,n}$ is the number of flips until you have flipped at least $m$ heads and $n$ tails,
$$E[W_{m,n}]=\frac mp+\frac nq-\sum_{i=0}^{m-1}\sum_{j=0}^{n-1}\binom{i+j}ip^iq^j$$
and in particular
$$E[W_{m,1}]=\frac mp+\frac{p^m}q.$$
{"set_name": "stack_exchange", "score": 5, "question_id": 3516841}