Microsoft Interview Question
Software Engineer in TestsI don't agree with that, we need to see the probability of transfer, and rashi's solution seems best.
Answer is B because when from Bag A 3 red balls are transferred to Bag B we know that those 3 balls are RED for sure. So, after first transfer the Bag B has 10 green + 3 Red balls.Now, from Bag B transfer 3 balls to Bag A.This time, 3/13 probablity that the chosen 3 balls are all red and 10/13 probability that the chosen balls are not all Red ( may be a mixture of red and green or may be all green). So, if 10/13 prob is there for the second case then Bag B has the more number of balls of other color than Bag A.
caro224 is right. It is not possible that one of them has more other's balls than another bag. The probability is 1.
Select 3 balls from B that are all red P(all_green)=C(3,10)/C(3,13) = 120/286;
Select 3 balls from B that are has 2 red P(2_green)=C(2,10)*C(1,3)/C(3,13) = 135/286;
Select 3 balls from B that are has 1 red P(1_green)=C(1,10)*C(2,10)/C(3,13) = 30/286;
Select 3 balls from B that are has no red P(all_red)=C(1,10)*C(2,10)/C(3,13) = 1/286;
In all cases, the two bags contain same number balls of other color. P = sum of all P(x) = (120+135+30+1)/286 = 1.
Think answer is: B
Possibilities:
B=>A movement, Four possible outcomes.
3 Green + 0 Red = ((10/13) * (9/13) * (8/13))
2 Green + 1 Red = ((10/13) * (9/13) * (3/13))
1 Green + 2 Red = ((10/13) * (3/13) * (2/13))
0 Green + 3 Red = ((3/13) * (2/13) * (1/13))
As one can see the probability of more no. Red is decreasing but there it is still there and significant.
lets make the case simple:
2 green balls in a bag A
2 red balls in the bag B
pick one from A and put in bag B
bag B has 3 balls ... probability of garbing red (2/3) or green (1/3)
so the answer should B
Correct me if i am wrong .. there is no point considering the possibilities cos the interview might have increased the number of balls hence the number of possibilities would have increased so no point counting them ... we are not calculating exact probability !! the question is what are the chances which will have more
At the end of the experiment,
both bags will have the same number of balls of that color and the same number of balls of the other color.
For ex:
R bag will have x R and 10-x G balls.
G bag will have x G and 10-x R balls.
Both bags will have more balls of that color and less balls of the other color.
After first xfer, A has 7R, B has 10G,3R.
Now, B has more other balls == 3. To match this, 3 G balls have to go to A. Well, not exactly because it depends if an R ball goes back from B to A! If so number needed to match will decrease. So the various sequences which can reduce this number needed to match is:
P{R,G,G} + P { R,R,G} + P { R,R,R} + P { G,G,G } --- (1)
First 2 terms above can happen in 3 ways i.e. R can be first, second or 3rd pick. Similarly for 2rd term i.e., G can be first second or 3rd pick. Last 2 terms can happen only in 1 way each.
3*(3/13*10/12*9/11) + 3*(3/13*2/12*10/11) + (3/13*2/12*1/11) + (10/13*9/12*8/11) = 1716/1716 = 1. Actually this is clear simply by examining (1).
In general, one with more intuition can see the above clearly (Not me!) The above formulation give us an intuition that if there are x other balls to start with, it will take x transfers to equalize the number of other balls! I think this can also be proved by induction!
It doesn't matter what we do with balls. If each bin has 10 balls, both bins will always have the same number of "other" color balls. For example, if bag A has 2 green balls, than means that bag B would have 2 red balls, etc. There is no chance that any bag has more balls os other color.
both will have same number of balls.
4 cases:
1--> 0 red ball transferred --> bag a has 3 green and bag b has 3 red.
2--> 1 red ball transferred --> bag a has 2 green and b has 2 red.
3--> 2 red ball transferred --> bag a has 1 green and b has 1 red.
4--> 3 red ball transferred --> bag a has 0 green and b has 0 red.
What if there are 3 bags with 10 green,red and blue balls in each? You take 3 from first and put it to second, then shuffle and take 3 from second and put 3 balls from second to 3rd, then shuffle and put 3 balls from 3rd bag to first one. Whats probability of having all bags the same number of "alien" (other color) balls?
After three red balls moved to green bag we have:
Bag1 Bag2
7R 10G+3R
There are 8 possibilities to choose 3 balls from bag2 (which contains 10G+3R):
1. GGG
2. GGR
3. GRG
4. RGG
5. RRG
6. RGR
7. GRR
8. RRR
Each possibility is equally probable, so:
P(choosing 3G) = P(choosing 3R) = 1/8
P(choosing 2G+1R) = P(choosing 1G+2R) = 3/8
So after moving three balls from bag2 to bag1 we have the following possible configurations with their probabilities:
Bag1 Bag2
10R 10G (we moved 3R) P = 1/8
9R+1G 9G+1R (we moved 2R+1G) P = 3/8
8R+2G 8G+2R (we moved 1R+2G) P = 3/8
7R+3G 7G+3R (we moved 3G) P = 1/8
As we can see, the probabilities are completely symmetrical, so the answer is:
"None of the bags is likely to have more of the number of balls of the other color".
After three red balls moved to green bag we have:
Bag1 Bag2
7R 10G+3R
There are 8 possibilities to choose 3 balls from bag2 (which contains 10G+3R):
1. GGG
2. GGR
3. GRG
4. RGG
5. RRG
6. RGR
7. GRR
8. RRR
Each possibility is equally probable, so:
P(choosing 3G) = P(choosing 3R) = 1/8
P(choosing 2G+1R) = P(choosing 1G+2R) = 3/8
So after moving three balls from bag2 to bag1 we have the following possible configurations with their probabilities:
Bag1 Bag2
10R 10G (we moved 3R) P = 1/8
9R+1G 9G+1R (we moved 2R+1G) P = 3/8
8R+2G 8G+2R (we moved 1R+2G) P = 3/8
7R+3G 7G+3R (we moved 3G) P = 1/8
As we can see, the probabilities are completely symmetrical, so the answer is:
"None of the bags is likely to have more of the number of balls of the other color".
they are same.
- caro224 October 22, 2008Think about how many red ball will move back to A.
if just one, then A have 2 green, b have 2 red,
if just two, then A have 1 green, b have 1 red,
if all three, A don't have green, b don't have red.