A fair coin is flipped $n$ times. What is the probability $p_k$, that the lead between "heads" and "tails" changes exactly $k$ times ?
For example, the sequence $$HHTTTHH$$ contains two changes because "heads" leads at the beginning, after $HHTTT$ , "tails" is in the lead and at the end, "heads" has the lead. A tie (equal number of throws with "heads" and "tails") is not considered as a change of a lead.
I tried to model this situation by a random walk. Then changing the lead means changing the sign of the value of the random variable in the process. But this did not lead anywhere.
This is covered in Feller's book, Introduction to Probability Theory and its Applications, Section III.5, Changes of Sign, Theorem 1.
He assumes the path length, $L$ say, is odd: if $L$ is even, the probability is the same as that for $L-1$ because there can be no change of sign on an even-numbered step. So, for path length $2n+1,$ the probability of exactly $r$ changes of sign (i.e. lead changes) he gives is:
$$\xi_{r,2n+1} = 2P(S_{2n+1} = 2r+1) = \binom{2n+1}{n+r+1}2^{-2n}.$$