Microsoft Interview Question
Software Engineer in TestsIf its 8 balls, Its possible to find the less weight ball in two steps :
1. Separate 2 balls first.
2. Weight remaining 3-3 balls and if both set are equal
weight other two and you can find less-weight one and END.
If both are not same - take less set.
3. Separate 1 ball and take other two and weight those.
1. Divide into groups of 27, 27 and 26
2. Weight 27 against 27, its either group with 27 or 26. For Ex, lets take 27
3. Divide into 9, 9 and 9
4. Weigh 9 against 9, we know group 9 balls which are heavier
5. Now divide them into 3,3,3
6. Similarly we will end up with group of 3
7. Divide into 1, 1, 1
7. Now compare 1 and 1...U know the answer
4 Steps! he he
1. Divide it into 30-30-20 & weigh 30-30.( WEIGH 1)
2. IF 30-30 weigh equal, divide remaining 20 into 8-8-4.
Weigh 8-8(WEIGH 2). After this its a 8 ball problem solved in 2 weighs. So TOTAL=4 WEIGHS.
3. ELSE
Divide 30 into 10-10-10 and weigh 10-10(WEIGH 2). Now out of 10 we need to find.
Divide 10 into 4-4-2. Out Of 4 we ll require 2 more weighs. TOTAL = 4 WEIGHS.
Assume the ball we need to find is X. Divide into 3 groups, A (27 balls), B (27 balls), C (26 balls)
- Anonymous May 01, 2010Step 1: Weight A vs B, whichever is heavier has X. If equal, then C has X. If C has X, choose a random ball in A and put into C so that C has 27 balls.
Step 2: After step 1, we determine which group has X, and the group size is 27. Divide into 3 smaller groups, each of size 9, and repeat the same procedure.
In short, we have, 80 -> 27 -> 9 -> 3 -> 1, 4 steps in total to find X.