expected number of coin flips given a condition 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?

Let $X_t$ denote the excess of heads over tails after the $t$th coin toss. 
Then this problem becomes a well-known result in the theory of random walks, that 
is solved using first step analysis. 
Let $f(x)$ be the expected number of steps needed for $X_t$ to reach $\{-N,N\}$
starting at state $x$.   This function satisfies 
$$f(-N)=0,\ f(N)=0,\ \text{ and } f(x)=1+{f(x-1)+f(x+1)\over 2} \text{ for }-N<x<N.$$
This forces $f(x)$ to be a quadratic, and since we know the two roots $-N$ and $N$, 
we conclude that $f(x)=(N+x)(N-x).$ In particular, at $x=0$ we get $f(0)=N^2$.
