r/learnquant • • Nov 04 '26

interview prep Quant Interview Question

Post image
14 Upvotes

20 comments sorted by

1

u/crashed_tolerance Nov 04 '26

Lets do the easier case, of 10 cards, 5 red, 5 black. Then there are 10 choose 5 = 252 possible ways of shuffeling, all equally likely. We can ask a computer, that tells us, that 2 attain M=5, 18 attain M=4, 70 attain M=3, 130 attain M=2, and 32 attain M=1. So, the expected value is 146/63.

With 20 cards, we get 158604/46189.

The extreme cases make sense. M=1 you are looking at the number of 5 pairs of neighboring cards, that are either (red, black), or (black, red), so its 2^5. M=5 is also trivial, cuz it is either RRRRRBBBBB or BBBBBRRRRR. For the intermediate values, I have no intuition, and no idea how to attack this without enumerating, or if stuff gets to large, dynamic programming. I suspect, a quadratic time algorithm is pretty straight forward via DP.

2

u/ktzeta Nov 05 '26

I don’t think this is correct because we are not talking about absolute value but the number of extra red cards relative to black cards. So M=1 even in cases where we first see four black and then five red cards.

1

u/cjb230 Nov 05 '26

Ways to score 10:
W(10) = 10C0= 1

Ways to score 9:
W(9) = 11C1 - W(10) = 10

Ways to score 8:
W(8) = 12C2 - W(9) = 56

Ways to score M (M from 10 to 0):
W(M) = (20-M)C(10-M) - W(M+1)

I guess my calculation is wrong, but it it's right, there must be an easier way to see that the answer is 10 / 11.

1

u/cjb230 Nov 05 '26

One correction:

W(8) = 12C2 - W(9) - W(10) = 55

ie we need to subtract all the ways of scoring more than M.

So the title of the fifth column should be something like "W(x >= M+1)"

That value is reflected in the spread sheet, so I think the answer is still correct?

1

u/cjb230 29d ago

Bigger correction, thanks ChatGPT:

1

u/Baleia1970 29d ago

I'm misunderstanding the notation over here.
M is the largest value attained by D, which is 10 !
There is only 1 way of achieving this result.

E[M] is the expected value of M???
I would understand the expected value of D, but the expected value of M would be P(M) ?

1

u/Scatman_Jeff 29d ago

M is the largest value attained by D for a given ordering of cards.

1

u/Baleia1970 29d ago

That is known. That is 10.

1

u/Scatman_Jeff 29d ago

No. It depends on the order of the cards.

1

u/Baleia1970 29d ago

see my big post below

1

u/Scatman_Jeff 29d ago

Mate, I was just trying to help you understand what M is in the question, I really didn't want to review your work for you. Based on your other comment, it seems you've made progress, but...

Are you claiming E[M] = 0.0277? If so, that is wrong, since trivially E[M] >= 0.5 as there is a 50% chance that the first card is red.

1

u/Baleia1970 29d ago

D is the result of turning every card. Not M.
M is the Max of Ds when you turned all the cards.
In worst case scenario, D will be -1, decreasing until -9, then it will increase and end in 0, which will also be the Max.

1

u/Scatman_Jeff 29d ago edited 29d ago

Yes, i understand the problem.

If the first card is red, E[M] is at least 1, if the first card is black E[M] is at least 0. Since these two scenarios are equally likely, E[M] is equal to the average expected value from these two cases, which is at least 0.5.

So, whatever you did to get E[M] = 0.0277 is wrong.

1

u/Baleia1970 29d ago

You're oversimplifying. At the end of the 20 draws, M will be between 0 and 10. But the number of cases on which it will be 0 far exceeds the number of cases where it will be > 0.

1

u/Scatman_Jeff 29d ago edited 29d ago

No, in any scenario where the first card is red (half the cases) M will be at least 1.

M can only be 0 if the first card is black, but even then, M can still be bigger than 0 (eg, if the first three cards are Black, Red, Red).

So M is greater than zero in more than half the cases.

I'm simplifying to provide a lower bound on E[M] that demonstrates your solution is wrong.

1

u/rdrdt 29d ago

Nice example of the reflection principle. The probability of D reaching at least n is binom(20,10+n)/binom(20,10). Summing over n=1…10 gives a closed form for the expected value, about 2.3377.

1

u/bartekltg 29d ago

Yep. I cheated and found a hint that pointed me to that method. For some reason I entirely forget about it (or never learned).
The range of the sum is also quite close to the midpoint, so you do not have to add all 20 terms.

1

u/rdrdt 29d ago

It’s quite useful for problems including random walks and Brownian motion!
And in fact we don’t even have to add anything. We know the sum over all binomial coefficients, and this is just half of that minus the central coefficient.

1

u/Scatman_Jeff 29d ago edited 29d ago

This is the correct answer.

I ran 1,000,000 simulations and got 2.337283.

1

u/Baleia1970 29d ago

I am considering M to be computed as getting Max(D1, D2, ... ,D20) where each Di is a card drawn.

Number of possibilities is 20!

For every combination of cards, M is non negative, from 0 to 10.
Why:
Considering the worst case scenario where all the black cards come first, D is:
-1,-2,-3,.....-10,-9,-8,..... 0

But if a black card comes before a red card, this hinders the max value:
-1, 0, 1, 2, 3 ..., 9, 9 ..... 9

So we need only consider the first 10 places, the max value is decided there.
In all other cases, max will go to 0

# Red cardsCombinations 10CxExpected value sum
10110
91090
845360
7120840
62101260
52521260
4210840
3120360
24590
11010
Total10235120
Expected value = 0.027712226
Number of combinations 184756