Cracking the Coding Interview: Fourth Edition (308 page e-book / PDF)
Delivered instantly as a PDF via email. For Software Engineers & SDETs
  • 150 programming interview questions and answers
  • 5 proven approaches to crack algorithm questions
  • 10 mistakes candidates make, and how to avoid them.
  • How to prepare for technical and behavioral questions without wasting your time!
"The BEST book for acing your interview. It helped me land my Microsoft job, and it was worth every penny!" - Ravi (Accepted at Microsoft, Amazon and Facebook) 30 Day Money Back Guarantee: Don't love the book? We'll give you your money back! More Info

Saturday, April 24, 2010

N red balls

Given n red balls and m blue balls and some containers, how would you distribute those balls among the containers such that the probability of picking a red ball is maximized, assuming that the user randomly chooses a container and then randomly picks a ball from that.

7 comments:

  1. ake all your N red balls and put them one by one in one container after another until you have no balls left. If there are containers left (i.e. without red balls), take your blue balls and distribute them as you like into the remaining containers. If there are no containers left, take all your blue balls and put them in one arbitrary container.

    ReplyDelete
  2. keep red ball in one container and remaining balls in other.
    the probability of container having red ball is 1.
    and the other is (n-1)/(n+m-1).

    ReplyDelete
  3. can u elaborate this

    ReplyDelete
  4. Put all blue balls in one container.. And distribute the red balls equally in all containers including the one selected for blue balls. In this case, if you have X containers.. Probability of selecting the container having blue balls is just 1/X.. where probability of red ball containers is (X-1)/X.. And even if the container having blue balls is selected at the worst case, you have a minimal probability of getting red ball from there also as we distributed the red balls equally in all containers...

    ReplyDelete
  5. put all blue balls in one container..and put one red ball in each of the remaining containers...the remaining red balls put in the container containing blue balls..

    ReplyDelete
  6. i agree with above solution......

    ReplyDelete
  7. ANS:-
    nswer:-
    Put one red ball in each of x containers. Now put the left red balls that is n – x in the last container and all blue balls in the same container.

    Now the probability of the red ball is increased.

    PS- The number of red balls has to be more than the number of containers.

    ReplyDelete