## Microsoft Interview Question for Software Engineer in Tests

• 0

Comment hidden because of low score. Click to expand.
3
of 3 vote

they are same.
Think 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.

Comment hidden because of low score. Click to expand.
0

Thank you!

Best explanation!

Comment hidden because of low score. Click to expand.
0

Very simplistic solution.
Thanks Caro224!!

Comment hidden because of low score. Click to expand.
0

I don't agree with that, we need to see the probability of transfer, and rashi's solution seems best.

Comment hidden because of low score. Click to expand.
0

Okey I analysed it agian and looks like you're correct :)

Comment hidden because of low score. Click to expand.
0

Perfect !

I got the same explanation when I tried. :)

Comment hidden because of low score. Click to expand.
1
of 1 vote

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.

Comment hidden because of low score. Click to expand.
0

You have to take the probability when among three balls
2 are red 1 is green.
1 is red 2 is green.
all green.

Comment hidden because of low score. Click to expand.
1
of 1 vote

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.

Comment hidden because of low score. Click to expand.
0

@kulang typo. Should be
P(1_green)=C(1,10)*C(2,3)/C(3,13) = 30/286;
P(all_red)=C(1,3)/C(3,13) = 1/286;

"Select 3 balls from B that are all <red> P(all_green)=C(3,10)/C(3,13) = 120/286;"
<> portion should be green

Comment hidden because of low score. Click to expand.
0
of 0 vote

Please correct me if I am wrong !

Comment hidden because of low score. Click to expand.
0
of 0 vote

a(red)+b(green)=10 in the first
c(red)+d(green)=10 in the second
a(red)+c(red)=10 totally 10 red
so b=c,a=d

Comment hidden because of low score. Click to expand.
0
of 0 vote

I should said the probability = zero.

Comment hidden because of low score. Click to expand.
0
of 0 vote

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.

Comment hidden because of low score. Click to expand.
0

Hi Satish,

I feel that the answer is that both the bags will have equal number of other balls. This can be done by simple probabilistic analysis.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Answer is there shuld be equal number of both balls in bag

Comment hidden because of low score. Click to expand.
0

In movement for B=>A there are four choices.
How can it be certain?

Comment hidden because of low score. Click to expand.
0
of 0 vote

Both bags have equal number of others balls

Comment hidden because of low score. Click to expand.
0
of 0 vote

Although there are four choices(probabilities), each choice make both bag have same numbers(3, 2,1, or 0) balls of other one's color.

Comment hidden because of low score. Click to expand.
0
of 0 vote

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)

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

Comment hidden because of low score. Click to expand.
0
of 0 vote

Equal Probability!

Comment hidden because of low score. Click to expand.
0
of 0 vote

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.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Anonymous above is me.

Comment hidden because of low score. Click to expand.
0
of 0 vote

I am 100% sure that my answer is correct as I was asked the same question in one of the interviews in my home country and I answered this wrong by then and the interviewer corrected me saying this answer. It was 3 years ago.

Comment hidden because of low score. Click to expand.
0
of 0 vote

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!

Comment hidden because of low score. Click to expand.
0
of 0 vote

Suppose x red in bag A
y green in bag A

Then 10-x red in bag B
10-y green in bag B

So, asking the possibility of |x- y| vs |(10-x)-(10-y)|, is not that obvious?

Comment hidden because of low score. Click to expand.
0
of 0 vote

No matter how you shuffle it. The answer will not change.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Why do we need to shuffle bag A in the first place???!!! XD

Comment hidden because of low score. Click to expand.
0

I don't get it either. Up.
In fact, I don't get the whole story.

Comment hidden because of low score. Click to expand.
0
of 0 vote

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.

Comment hidden because of low score. Click to expand.
0
of 0 vote

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.

Comment hidden because of low score. Click to expand.
0
of 0 vote

finally, there are 10 balls in each bag.
If there are X number of green balls in Bag A, it must mean that there are X number of red balls in Bag B.

Comment hidden because of low score. Click to expand.
0
of 0 vote

caro's explanation is correct abd after the final transfer both the bags will have equal number of balls of OTHER color.

Comment hidden because of low score. Click to expand.
0
of 0 vote

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?

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````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".``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````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".``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.