NVIDIA Interview Question
Software Engineer / DevelopersSplit balls into three sets: 2x sets of 3 balls each, and 1x set of 2 balls
First scale step: compare both sets of 3 balls. If one side is lighter, that 3-balls set goes to second step. If both sides are same, the set of 2-balls goes to second step.
Second scale step: If chosen set has two balls, just weigh and pick the lighter. If chosen set has 3 balls, compare any two and pick the lighter one, if they are same, then the third ball in the set.
I feel this is even simpler: - 2 sets x 4 balls = less groups. 1) Place one set of 4 balls on scale - record weight
2) Place second set on scale- record weight. = The group with the smaller weight hence has the smaller ball.
3) Divide the heavier group by 4.
4) From the lighter group of 4- Place 2 random balls on scale. = If this number is half of the homogeneous set then disregard
5) Chose the the group of in which is not eliminated by common factor- Drop one ball on the scale and if this is a factor then it is the seventh identical ball.
4 physical steps. If you can precisely do it easier please post!
there are 2 cases this:
make three sets 3,3,2. scale 3,3
case 1: if both are equal, take set of 2 and take the ligther one. here the task completes in 2 steps.
case 2: if both are not equal, take the set of 3 which is lighter, now take any two out of those. if 2 are equal the left one will be the lighter.
number of steps tends to be cube root of the number of balls.
separate the initial set into three groups, one for each side of the scale and one to be kept aside.
if the scale shows equal, you know the lighter one is in the set set aside.
if the scale tips one way, you know the lighter is in the set that the scale tipped away from.
solve recursively.
Always 3 groups,coz you can eliminate 66% in one weigh.
Guys,reply if you have different idea?
pick any 6 balls divide them into 3 each.
- Punit Jain May 06, 2012if they are same check the rest two and you will find the heavier.
if they are not same then choose 3 from heavier bowl and pick any two and weigh them, if they are same third one is heavier otherwise its clear.
so you have to weigh only two times.