TITLE: expected number of coin flips given a condition
QUESTION [7 upvotes]: I have a fair coin, and I flip it until the following condition is met:
#heads - #tails = N  OR  #tails - #heads = N

where $N \geqslant 2$.
What is the expected number of times I flip the coin?

REPLY [5 votes]: This is an answer which contains a lot of "modern" probability in it and should serve as a motivation to study measure-theoretic formulation of probability.
Consider $S_n$ to be a random walk, i.e. a process on $\mathbb{Z}$ such that it starts at $0$ and at each step moves $+1$ or $−1$ with equal probability
We are interested in $\mathbb{E}[T]$, where $T=\min \{n : |S_n|=N \}$. $T$ is an example of a stopping time.
It can be shown that $(S_n)_{n\geq0}$ and $(S_n^2-n)_{n\geq0}$ are both martingales. Application of an appropriate version of Optional Stopping Theorem yields:
$$0=\mathbb{E}[S^2_T-T]$$
Clearly $\mathbb{E}[S^2_T]=\frac{1}{2}N^2+\frac{1}{2}N^2=N^2$, because random walk is symmetric, and hence the answer.
There are crucial details omitted in the application of the Optional Stopping Theorem, so this is not a complete answer by any means.