You are given two bags, and 10 marbles, 5 are black, 5 are white. You have to put the marbles into the two bags, and then the interviewer (I guess?) shuffles the bags and lets you pick a a bag to select a marble from. You "win" if you get a black marble (or white).
The problem is essentially: how do you distribute the ten marbles between the two bags to maximize you probability of getting a specific color.
My first answer was to point out the window behind him and say "look a zeppelin!" and he turned :D
Like all such problems the actual answer is obvious once you realize it or if you already know it.
> Like all such problems the actual answer is obvious once you realize it or if you already know it.
I believe this problem is really trying to get you to formulate an abstract problem mathematically. It's not a trick question, it can be solved with math.
In this problem we can start with all 10 marbles in one bag (bag A). We have two degrees of freedom: how many black marbles to put in the other bag (bag B) (call this variable b) and how many white marbles to put in the other bag (call this variable w).
0 <= b <= 5
0 <= w <= 5
1 <= b + w <= 9 (can't have everything in one bag)
These three constraints form a hexagon.
Probability of picking black from bag A: (5-b)/(10-b-w)
Probability of picking black from bag B: b/(b+w)
Probability of picking black given probability of picking bag A = 0.5: 0.5((5-b)/(10-b-w)) + 0.5(b/(b+w))
Now we know that the problem has two symmetries, bag A vs bag B (b = w) and white vs black (b+w = 5) so our hexagonal solution space must also be symmetric with probability = 0.5 along those lines. This leaves just 6 points to evaluate: (w=0, b=1), (w=0, b=2), (w=0, b=3), (w=0, b=4), (w=1, b=2), (w=1, b=3)
Manually calculating the probability at each we find that the respective probabilities are ~ 0.722, 0.688, 0.643, 0.583, 0.547, 0.542
This means the best probability of picking a black ball is obtained when 1 black ball is moved to the other bag.
Its a simple analytical question to see if you can perform simple optimization under constraints. It exercises your analytical skills without requiring any particular mathematical background.
Any high level engineering job will involve some proficiency with computing expectations and solving constrained problems, for scaling or building supply chains. Programming is not necessarily a skills based trade like carpentry, some high level thinking always helps.
Straight up engineering IC position (webkit many many many many years ago, long before chrome existed, before safari for windows, before ye olde iphone)
Do you know the winning color beforehand and does your selection of the bag allow you to physically handle it? If so, you put one marble of the winning color in one bag, all the rest in the other, and then you select the lighter bag.
This is quite good question with an intuitive answer (at least to me): 50%/50% marble distribution maximizes the chances of getting specific color with a random selection.
Unless you are allowed to ask questions or gain some prior knowledge, isn't the outcome of picking a black marble (given that you have to put all marbles into the bags) 50%?
You can’t do that though. There are only 5 marbles of each colour so there’s no way to split them so that both bags have the same distribution. Thus your closest to 50/50 would be 2 black and 2 white in one bag, 3 black and 3 white in the other, giving you a 0.5 probability of guessing correctly.
You’re better off putting one black marble into one bag and all of the rest of the marbles into the other. That way if you pick the bag with just one marble you win by default and if you pick the other bag you have a 4/9 probability of getting a black one. This gives you a total probability of 13/18 = 0.72.
This type of question is like magic trick. The questions sets up a "familiar stage" or 'context' to limit your thinking. It's up to you to do the magic trick.
Hmm, I think 50/50 is the worst you could do. What if you put 1 black marble in 1 bag and the other marbles in the other bag. Then even a random choice would get you .5 * 100% + .5 * 4/9 = 72.2%
And also, if you can look at or touch the bag before picking it, then just pick the one the looks like it has only 1 vs. 9 marbles!
You can definitely do worse than 50/50: just flip your solution and put a single white marble in one of the bags. By the way, your solution--single black marble in one bag, all other marbles in the other bag--is optimal; do you know of a way to prove it? Besides just exhaustive enumeration, that is.
Exhaustive enumeration is a proof even if it's not very satisfying :-). For example, a big part of the Four colour theorem is a big enumeration of all configurations.
wouldn't putting one black marble in one bag and all the others into the second bag give you the highest chance of being able to draw a black marble? .5 * 1 + .5 * 4/9 = .72
You are given two bags, and 10 marbles, 5 are black, 5 are white. You have to put the marbles into the two bags, and then the interviewer (I guess?) shuffles the bags and lets you pick a a bag to select a marble from. You "win" if you get a black marble (or white).
The problem is essentially: how do you distribute the ten marbles between the two bags to maximize you probability of getting a specific color.
My first answer was to point out the window behind him and say "look a zeppelin!" and he turned :D
Like all such problems the actual answer is obvious once you realize it or if you already know it.