Expected Number of Runs in Coin Tosses
Company: Goldman Sachs
Role: Data Scientist
Category: Statistics & Math
Difficulty: easy
Interview Round: Online Assessment
# Expected Number of Runs in Coin Tosses
A fair coin is tossed 21 times. A run is a maximal consecutive block of identical outcomes. For example, `HHHTTH` contains three runs: `HHH`, `TT`, and `H`. Find the expected number of runs.
### Constraints & Assumptions
- Tosses are independent and each side has probability one half.
- Every nonempty sequence begins with exactly one run.
### Clarifying Questions to Ask
- Is the coin fair and are tosses independent?
- Is a run counted once regardless of its length?
```hint Count changes between neighbors
After the first toss, a new run begins exactly when the next toss differs from the previous one.
```
### What a Strong Answer Covers
- An indicator-variable representation of the run count.
- The probability of a change at each adjacent pair.
- Use of linearity of expectation without assuming the indicators are independent.
- The final numerical expectation.
### Follow-up Questions
- What is the expectation for `n` tosses of a coin with head probability `p`?
- How would you compute the variance of the number of runs?
Quick Answer: Compute the expected number of same-side runs in 21 coin tosses, where a run is a maximal consecutive sequence of identical outcomes.