Jane Street Interview Question

Flip the coins, the expected time to get HHT

Interview Answers

Anonymous

Jan 3, 2017

Let x_i be the probability a random infinite binary sequence has its first HHT ending at position i. Clearly x_i =0 for i=1,2 and x_i=1/8 for i=3,4,5 and we can deduce the recurrence x_i=1/8(1-x_{i-3}-...-x_1) for i>=3. Since the sum of all x_i is 1 we can write x_i = 1/8(x_{i-2}+x_{i-1}+x_i+...) so x_3+x_4+x_5+... = 1/8 (x_1+2x_2+3x_3+...) so multiplying both sides by 8 we get that the expected number of flips is 8.

11

Anonymous

Feb 13, 2017

This is incorrect. You cannot bracket like this. Condition on the first 2 steps and you will see that the expected number of steps to get HHT is 14.

3

Anonymous

Sep 13, 2017

Here is another approach to this problem using conditional expectation. Let X be the minimum number of flips needed to get the first run of HHT. Let HH denote the event that the first two flips land on heads and similarly define TH, HT, TT. Then using a well known theorem, we can write E[X] as E[X] = E[X | HT] P(HT) + E[X | TT] P(TT) + E[X | HH] P(HH) + E[X | TH] P(TH) where E[X | Z] is the conditional expectation of random variable X with respect to random variable Z and P is the probability measure. It is easy to see that E[X | HT] = E[X | TT] = E[X] + 2, and P(HH) = P(HT) = P(TT) = P(HT) = 0.25. Using the above theorem for E[X | HH], E[X | TH] and a little observation, we obtain E[X | HH] = 4 and E[X | TH] = 0.5 * E[X] + 4 The first equation then implies E[X] = 8.

1

Anonymous

Oct 30, 2017

8 is the correct answer...this can be solved by viewing it as a renewal reward process. Suppose we get a reward 1 each time we get HHT, then intuitively in the long run we can get 1/8 (=p(H)p(H)p(T)) unit of reward per unit time. By the central limit theorem for renewal reward process, this should be equal to the expectation of reward for each period over the expectation of hitting time. But the expected reward for each period is just 1, so the expectation of hitting time is 8. This can be generalized to HTH, which is more interesting, because the reward for each period is not 1 anymore: if we get a HTH from previous period, then if the start of the new period is TH, we actually get HTH TH, the reward here should be 2. So the expected reward in this case is 1+p(T)p(H) = 5/4, and thus the expected hitting time is 10.

1

Anonymous

Jan 26, 2018

HHT = HH + T. After 2 consecutive heads (with E[HH] = 6), if we get H, we continue as we still have 2 consecutive H's, else we get desired HHT. So, E[T] = 2 and therefore, E[HHT] = E[HH+T] = E[HH] + E[T] = 6 + 2 = 8

Anonymous

Sep 7, 2017

Both are wrong. The answer is 10. let S_{i} = roll that came up after flipping -ith coin. Sequence we need: HHT let X = # of rolls required to get HHT if S[1] = T => then we need to start from beginning, (1 + x) * 0.5 (as we have 1/2 Prob of seeing T) if S{1] = H => then move on and evaluate 2nd position if S[2] = H => we are basically at the same state, so you didn't waste any flips..just wait until T comes. So, (x) * 0.5 if S[2] = T => then you can proceed to next. if S[3] = H => then you reached the final spot; it took 3 steps to get here. if S[3] = T => then whole sequence breaks down, so you need to start from the beginning 0.5 * (x+3) So, the entire equation looks like: X = 0.5*(X+1) + 0.5 * { (0.5*X) + 0.5* { (0.5 * 3) + (0.5 * X)} } if you expand above, you get X = 10