Showing posts with label Interview question. Show all posts
Showing posts with label Interview question. Show all posts

Thursday, August 28, 2008

contaminated pill problem

Q: You have 4 jars of pills. Each pill is a certain weight, except for contaminated pills contained in one jar, where each pill is weight + 1. How could you tell which jar had the contaminated pills in just one measurement?

A: weight p1 + 2* p2 + 3*p3 + 4*p4
if the total weight is 10weight + i, the ith jar is contaminated.

gold bar problem

Q: You've got someone working for you for seven days and a gold bar to pay them. The gold bar is segmented into seven connected pieces. You must give them a piece of gold at the end of every day. If you are only allowed to make two breaks in the gold bar, how do you pay your worker?

A: you need 1 for the first day
you need 2 for the second day.
so you have 1, 2, 4
and can pay 1, 2, 1+2, 4, 4+1, 4+2, and 4+1+2 for the seven days.

three envelop problem

Q: 三张信封(A,B,C),只有一封有$10000。你可以任选其中一封,譬如B,剩下两封必有一 封为空,譬如A,现在取走A,剩下两封。 问:你是stick to你的选择(B),还是选择剩下的另外那封(C)?

A: pick C.

p(B=$) = 1/3.
p(C=$) = 1 - p(B=$) - p(A=$) = 1 - 1/3 - 0 = 2/3

Tuesday, August 26, 2008

Card dealing question

Q: In how many ways can a pack of 52 cards be dealt to 13 players, 4 to each, so that one player has a card from each suit but no one else has cards from more than one suit?

A: Three steps:
1. pick one player, pick one card from each suit
==>13^5
2. put 12 remaining players into 4 different suits to make three players per suit
==> 12!/(9!*3!) * 9!/(6!*3!) * 6!/(3!*3!) = 12!/(3!)^4
3. put 12 remaining cards in each suit to 3 players, separately
==> (12!/*8!*4!) * 8!/(4!*4!))^4 = (12!)^4 / (4!)^12

so final answer is: (13!)^5 / (4!)^12 / (3!)^4