30 Day Risk-Free Guarantee:
100% money back if you're unsatisfied.
Book (308 Pages):
  • 150 Programming Interview Questions and Solutions
  • Five Proven Approaches to Solving Tough Algorithm Questions
  • Ten Mistakes Candidates Make -- And How to Avoid Them
  • Steps to Prepare for Behavioral and Technical Questions
  • Interview War Stories: A View from the Interviewer's Side
  • Book Preview and More Info

Video (One Hour):
  • Watch CareerCup's founder perform a totally unscripted technical interview of a candidate.
  • Overview of what interviewers look for in software engineering jobs.
  • Technical questions with white-boarding coding where the candidate does well - and struggles.
  • Interviewer reviews with what went well and poorly.
  • Video Preview and More Info

Resume Review (24 - 48hr)
  • Get your resume reviewed by a trained engineering interviewer. More Info
All Products / Services


Express Prep Package (Book)
$29.99 for e-book | $32.45 for paperback
Buy E-Book Buy on Amazon


Standard Prep Package (E-Book & Video)
Emailed Instantly | $39.99
Buy Standard

Elite Prep Package (E-Book, Video & Resume)
Emailed Instantly | $99.99
Buy Elite
 



Bag A = 10 Red balls.
Bag B = 10 Green balls.

Shuffle bag A move three balls from A => B then
Shuffle bag B move three balls from B => A

Which bag is likely have more number of balls of other color.

32


Rashi on October 22, 2008 |Edit | Edit

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.

Rashi Gupta on October 22, 2008 |Edit | Edit

Please correct me if I am wrong !

caro224 on October 22, 2008 |Edit | Edit

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.

Anonymous on December 06, 2008 |Edit | Edit

Thank you!

Best explanation!

Anonymous on March 03, 2009 |Edit | Edit

Very simplistic solution.
Thanks Caro224!!

Cheema on April 30, 2009 |Edit | Edit

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

Cheema on April 30, 2009 |Edit | Edit

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

peace on November 12, 2009 |Edit | Edit

Perfect !

I got the same explanation when I tried. :)

Anonymous on October 22, 2008 |Edit | Edit

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

kulang on October 23, 2008 |Edit | Edit

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.

kulang on October 23, 2008 |Edit | Edit

I should said the probability = zero.

Satish on October 23, 2008 |Edit | Edit

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.

Rahul on October 28, 2008 |Edit | Edit

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.

Aryan on October 23, 2008 |Edit | Edit

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

Satish on October 23, 2008 |Edit | Edit

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

SB on October 23, 2008 |Edit | Edit

Both bags have equal number of others balls

kulang on October 23, 2008 |Edit | Edit

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.

Roy. on October 24, 2008 |Edit | Edit

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

Anbe on October 24, 2008 |Edit | Edit

Equal Probability!

Anonymous on October 24, 2008 |Edit | Edit

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.

Anbe on October 24, 2008 |Edit | Edit

Anonymous above is me.

Anbe on October 24, 2008 |Edit | Edit

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.

acoader@gmail.com on October 26, 2008 |Edit | Edit

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!

Anonymous on November 04, 2008 |Edit | Edit

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?

Anonymous on November 04, 2008 |Edit | Edit

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

Anonymous on November 11, 2008 |Edit | Edit

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

XYZ on November 21, 2008 |Edit | Edit

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

Yuri on December 19, 2008 |Edit | Edit

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.

mayank on June 03, 2009 |Edit | Edit

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.

junma on August 07, 2009 |Edit | Edit

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.

googler on August 13, 2009 |Edit | Edit

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

celicom on December 21, 2009 |Edit | Edit

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?

Add a Text Comment | Add Runnable Code
Name:
Comment:

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








Amazon (1033)Bloomberg LP (403)Qualcomm (117)Adobe (88)Goldman Sachs (78)NetApp (49)IBM (43)Morgan Stanley (33)CapitalIQ (30)Sophos (25)Achieve Internet (23)Electronic Arts (19)Motorola (18)Research In Motion (17)Flipkart (16)
Microsoft (867)Google (141)NVIDIA (98)Yahoo (82)Epic Systems (69)Expedia (47)VMWare Inc (43)Apple (32)Cisco Systems (28)Facebook (23)Infosys (22)Agilent Technologies (19)Sage Software (17)Deshaw Inc (16)FlexTrade (15)
More Companies »
Software Engineer / Dev... (1062)Financial Software Deve... (170)Testing / Quality Assur... (56)Analyst (35)Virus Researcher (25)Field Sales (15)Developer Program Engin... (9)Front-end Software Engi... (6)MyJoB (5)area sales manager (4)Assistant (3)Cabin crew (2)Accountant (1)personnel (1)Intern (1)
Software Engineer in Te... (288)Program Manager (65)Development Support Eng... (47)INTERN(MSIDC) (28)Web Developer (18)System Administrator (10)Consultant (10)Production Engineer (5)Associate Technology L2 (5)AcquireKnowledge (4)Product Security Engine... (3)Solutions Architect (2)Gamer (1)mts (1)Fresh graduate interview (0)
More Job Titles »
Algorithm (1073)Terminology & Trivia (294)C (166)Object Oriented Design (159)Java (121)Testing (114)Arrays (101)Operating System (78)Database (70)Linked List (62)String Manipulation (56)Networking / Web / Inte... (44)Threads (36)Linux Kernel (33)PHP (22)
Coding (511)C++ (204)Behavioral (159)Data Structures (155)Experience (116)Brain Teasers (111)Computer Architecture &... (79)General Questions and C... (73)Trees and Graphs (69)Math & Computation (57)Application / UI Design (45)Ideas (38)System Design (35)Puzzles (30)Bit Manipulation (20)
More Topics »
CareerCup Official Interview Book Daily Questions Requests for Help Mock Interviews Video for Cracking the Coding Interview Job Placement Service CareerCup Blog
My Profile Edit Profile & Email Settings Sign Out