Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: In-Person
Divide 8 balls into:
Set A: (3)
Set B: (3)
Set C: (2)
Comparison 1: A and B
if(A=B):
Compare Set C, Keeping one ball in each Pan and find the wrong one!
else:
Either A or B has to has Odd one!
Compare two balls: B1 and B2 and
if(B1=B2): B3 is thewrong one
else: B2/ B1 will be the wrong one :)
Name the balls as 1,2,3,4,5,6,7,8
Pick first 6 (or any 6) balls and put on either side of balance
Case 1:
If it matches then take remaining to balls say 7 and 8 and put on either side.
Now which ever is heavier is the one
Case 2:
If first 6 does not match, then take the 3 balls from heavier side and pick any 2 of them and weigh it.
Case A:
If not same then the heavier is one.
Case B:
If same then the remaining 3rd ball is the heavier one
Name the balls as 1,2,3,4,5,6,7,8
Pick first 6 (or any 6) balls and put on either side of balance
Case 1:
If it maches then take reaminig to balls say 7 and 8 and put on either side. Now which ever is heavier is the one
Case 2:
If first 6 does not match, then take the 3 balls from heavier side and pick any 2 of them and weigh it.
Case A:
If not same then the heavier is one.
Case B:
If same then the remaining 3rd ball is the heavier one
Name the balls as 1,2,3,4,5,6,7,8
Pick first 6 (or any 6) balls and put on either side of balance
Case 1:
If it matches then take remaining to balls say 7 and 8 and put on either side. Now which ever is heavier is the one
Case 2:
If first 6 does not match, then take the 3 balls from heavier side and pick any 2 of them and weigh it.
Case A:
If not same then the heavier is one.
Case B:
If same then the remaining 3rd ball is the heavier one
1> Place 3 balls on each side of balance
- hprem991 April 24, 20132> If it is balanced, Put the remaining 2 of the balls on the second iteration and find the different.
3> If not balances, take out the 3 balls of the side which is heavier and put 2 balls among these 3 in the second iteration.
4> If it is balanced, the 3rd one is the heavy else, the one the one with the heavier side is heavy.