Expected Value Problem with a Polar Bear Using a Typewriter A polar bear starts to write an $80$ character word on a typewriter, where each
letter is equally likely to occur (no other symbols or spaces can occur,
just letters). I want to find out the expected number of times the phrase
"PANDA" occurs in the sentence.
I can see that "PANDA" can occur a maximum of  $\frac{80}{5} = 16$ times within
the word. I can see generally a sketch of how to get the first term, since
I originally thought that
I can place "PANDA" in $76$ spaces, then place the rest of the possible
letters $(26)^{75}$ ways. When we compare to the number of $80$-character
letter strings available, on initial guess, one would think that the first term
would be
$$\frac{76 (26)^{75}}{(26)^{80}},$$
but obviously this also counts the instances where "PANDA" also shows up
in the other $75$ characters in the string. Is there a reasonable way to
remove those observations from this term? I would like to know this so
I can also account for their removal in later terms. Otherwise, is there
a more reasonable way to compute this expected value?
 A: Just use lineality of expectation.
Let $s_1,s_2,\dots s_{80}$ be the characters typed by the polar bear.
Let the indicator random variable, $e_j$ , be $1$ if $s_j,s_{j+1},s_{j+2},s_{j+3},s_{j+4}$ spell PANDA.
The random variable you are looking for is $\sum\limits_{j=1}^{76}e_j$
Because for all $j$ : $\mathsf P(e_j{=}1)=1/26^5$, therefore its expectation is: $76~\mathsf E(e_1)=\dfrac{76}{26^5}$
A: Let's simplify the problem to finding the probability of writing a specific $5$ character string in $5$ characters. Clearly this is $26^{-5}$ since there are $26$ letters to choose from and each is independent.
So what if we're writing a specific $5$ character string within $10$ characters? We can write it either $0$, $1$ or $2$ times, with the last option being the string written twice, back to back starting at the $1$st and $6$th position. But we can ignore when the string comes up twice since that has the same effect on the expected value as if the string came up in either of those positions just once*. We already know that writing it once in the first $5$ characters has probability $26^{-5}$ and the same is true for it starting in any other place. So the probability of writing the string once is $6\cdot26^{-5}$ since it can start on any of the first $6$ positions. So our expected value will be $6\cdot26^{-5}$. Note that $6=10-5+1$.
Going back to the original problem, the probability of writing the string once is $26^{-5}$ but now we can write it in $80-5+1=76$ different places. Hence, the probability of writing it in any of them is $76\cdot26^{-5}$. And again, we can ignore the string being written twice, or any other number of times, for the fact that it has the same overall effect on the probability.
So, our final answer, as CarryOnSmiling said in fewer words is $76\cdot26^{-5}$. The bear would still need a specially made typewriter though. Drop me a comment if you think I've explained anything poorly.

*What I mean to say here is that if $A$ is that the string starts on the $1$st position but $B$ is that it does so on the $1$st and the $6$th then $P(A\cup B)=P(A)+P(B)-P(A\cap B)=P(A)$. The same would be true if $A$ were about the $6$th position instead.
