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.
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.
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.
~50/50 -> .5x(2/5) + .5x(3/5) = .5
~0/1 -> .5x0 + .5x1 = .5
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.
If so I would put all of one color in one bag, all of other color and 2 of the first color in other bag.
Now I have two different size bags one with all one color and one with very little of that color.
If I can pick bag and color I want I pick the small bag and say I want that color.
If I can't pick bag but I can pick color when they choose bag I choose whatever color is most likely to be in bag.
If I have no choice in anything I would always have the 50% chance of whatever color was assigned to me, this makes me assume I have some choice.
on edit: obviously distribution is an example, probably smartest distribution is one in one bag, rest in other bag.
on edit2: realized I described separation of colors poorly.
There is obvious answer.
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!
2) Put the white marbles in your pocket