Interview question: game stop if difference of H and T is k

probability

Here is an interview question:

A and B toss a fair coin. When (number of H) – (number of T) is k, the game stops and A win; When (number of T) – (number of H) is k, the game stops and B win. What's the probability that the game does not stop at 100 tossing.

If we denote +1 for tossing H and -1 for tossing T, the game stopping before 100 tossing is equivalent to the sum of score hits $y = k$ or $y=-k$ (begin at (0,0)) before $x=100.$ It seems related to the reflection principle but too complicate to apply for me.

Best Answer

I haven't been able to find a formula for this. As I said in a comment, it's not hard to show the the expected number of tosses is $k^2$, but that doesn't tell us the probability, of course. (If the current score is $s$, the expected number number of tosses to reach $\pm k$ is $k^2-s^2$.)

I computed the probabilities for $5\leq k\leq 30$. here they are:

5 0.008564661079288705
6 0.03743923046026554
7 0.10134714601942418
8 0.1770085936059219
9 0.2768616216761906
10 0.36126381746625985
11 0.45924135971549884
12 0.5313572971179236
13 0.613461193775431
14 0.6692807174732699
15 0.733588146410795
16 0.7745990334383873
17 0.8227482017723893
18 0.8516296346957396
19 0.8862241413927717
20 0.9057430944388616
21 0.9295995996875466
22 0.9422567030242259
23 0.9580425286452614
24 0.9659147974026073
25 0.9759340485492769
26 0.980628442581484
27 0.9867257589681478
28 0.9894085107300897
29 0.9929647165540598
30 0.9944332711858205

and here's a graph:enter image description here I did this by declaring that the game ends in a tie if there is no winner after $100$ tosses. Then we have a Markov chain with $3$ absorbing states, and I calculated the probability of absorption in the "tie" state.

I was surprised that with $k=20$, the probability of a tie was only $90.6\%$, since the expected number of tosses until some is ahead by $20$ is $400$. However, I simulated $100,000$ trials, and there were $90,806$ ties.

Now that I think of it, my first reaction to the question was, "Well, if I knew $k$, I just do a simulation." Perhaps that was the answer the interviewer was looking for.

I thought about computing first passage times, as I mentioned in a comment, but I thought I'd end up writing a script to calculate them anyway. The way I did it, making a state consist of the score and the number of tosses was overkill, especially since I included lots of unreachable states, but it was easy to program, and fast enough in execution.

ADDENDUM

To calculate the expected number of tosses, let $E(n)$ be the expected number of tosses to reach $\pm k$ if the current score is $n$. We know $E(k)=E(-k)=0$ and we want to compute $E(0)$. We have the recurrence $$E(n)= 1+\frac12E(n-1)+\frac12E(n+1),\ -k<n<k$$

Standard techniques give the solution $$E(n)=k^2-n^2$$ so $E(0)=k^2$.