Expected number of coin streaks Source: Quant interview.
You have a coin which comes heads with probability $1/5$, and you
toss it $700$ times. If there are multiple coins in a row (could be just
1), we call them/it a streak. For example, if we get HTHTT, we
have 4 streaks: first H, second T, third H, and last two T.
What is the expected number of streaks in $700$ tosses?
Attempt: I interpreted the number of streaks as the number of switch between either H to T or T to H in the sequence + 1.
The problem has a markov chain structure and I was able to obtain the following equations, given $S(n)$ number of strike in sequence with n coins: $S(n|H)=0.2S(n-1)+0.8(1+S(n-1))$ and $S(n|T)=0.8S(n-1)+0.2(1+S(n-1))$
This implies $S(n) = S(n|T)p(T) + S(n|H)p(H) = S(n-1) + 8/25$ and therefore $E[S(700)]=224$.
This solution matches some numerical simulations but always underestimates a bit (e.g. with $10^6$ iterations I get $224.64$ and also smaller $n$ tend to underestimate).
 A: The chance of a switch is $1/5$ if on a tail, and the chance of the coin being a tail is $4/5$, and the chance of a switch is $4/5$ if on a head, and the chance of it being a head is $1/5$, so the expected number of switches is just $2\times1/5\times 4/5\times (700-1)=223.68$ where we subtract 1 from 700 since the first coin cannot be a switch.
A: Calculating the expected number of switches is actually pretty elementary once you remember that expectation is linear.
Let $X_i$, for $2\leq i\leq 700$, be the random variable which is $1$ if the $i$th coin is different from the one before it, and $0$ if it's the same. These are identically distributed (independence is irrelevant here). We get $$E(X_i)=P(X_i=1)=2\cdot\frac45\cdot\frac15=\frac{8}{25}$$
and the total expected number of switches is just
$$
E(X_2+X_3+\cdots+X_{700})=E(X_2)+E(X_3)+\cdots+E(X_{700})\\
=699\cdot E(X_2)=\frac{5592}{25}=223.68$$
This means that the expected number of streaks is $224.68$, which is pretty darn close to your Monte Carlo calculation of $224.64$.
A: If first toss is head , we expect a total of  $1.25$ tosses needed to get first switch .
Else first toss is tail ,  we expect a total of  $5$ tosses needed to get first switch .
See the pattern ?
we're luck today because $1.25(112) +5(112)= 700$ .
IMO Your interviewer will be :) since that's exactly what he wants you to do .
