Bloomberg LP Interview Question
Software Engineer / DevelopersDivide 9 balls in 3 groups of 3 each, call them G1, G2, G3
1) First Measurement: First weight G1 and G2 groups
If they are the same weight, G3 group contains the heavier ball, if not, the heavier of G1 and G2 contains the heavier ball.
Let's say G3 contains the heavier ball.
2) Pick G3
3) Second measurement: Choose and weight 2 balls from the G3 group
If both balls have same weight, the 3rd ball is heavy, otherwise the heavier ball will tip the scale more.
I think the entire talk of the medical scale is just bad terminology used by the interviewer. I am fairly certain he meant the weighing scale and want a solution that contains 2 measurements.
I guess that, the key is the medical-scale and how it weighs, unless its balancing we are not weighing, if its stuck as heavier than the marked weight or as lighter as the marked weight we are not weighing.
This is what I think.
1. Keep one stone apart, call it #9.
2. Take four stones say (1,2,3 and 4 ), put them on the platform and balance their weight, (slide the slider to the mark). Measuring#1. Now unless we balanced the weight again we are not measuring.
3. Now remove all the four stones and put other four (5,6,7 and 8 ), now if the scale balances the heavier is #9.
4. If the scale is unbalanced and stuck as heavier go to step# 5, if the scale is unbalanced as lighter go to step# 8.
5. Place #1 on platform, still the balance beam wont move, it will be stuck as heavier.
6. Now remove #5, if the scale balances #5 is the heavier one.
7. If the scale is still stuck as heavier, place #2 then remove #6, if balanced #6 is the heavy one, else if still stuck as heavier, place #3 then remove #7 if balanced #7 is the heavy one else #8 is the heavy one.
8. Remove #5 from the platform, still the balance beam wont move, it will be stuck as lighter.
6. Now place #1, if the scale balances #1 is the heavier one.
7. If the scale is still stuck as lighter, remove #6 then place #2, if balanced #2 is the heavy one, else if still stuck as lighter, remove #7 then place #3, if balanced #3 is the heavy one else #4 is the heavy one.
If what you say is true i.e. trying to balance the scale is what counts that just make 3 groups. 4-4-1.
- Balance the scale for the first group with 4 balls.
- Now put the second group on the scale. Don't touch anything on the scale.
- If it balances the lonely stone is the heavy one.
- If 2nd grp is heavier than we know that the lonely stone is OK. Balance the scale using that ball (second scaling). Now just check each stone in the 2nd grp and fine the heavier one.
- If 1st grp is heavier than we know that the lonely stone is OK. Balance the scale using that ball (second scaling). Now just check each stone in the 1st grp and fine the heavier one.
We could do it with only one scaling, couldn't we? Balance it, figure out either the left out ball as a normal one or a heavier one. If it's a normal one, we know the group which contains the heavier ball. Put the group with the heavy ball on the scale. It will not balance. Keep replacing until the scale balances and you figure out the heavier ball. Please correct me if I am wrong.
We could do it with only one scaling, couldn't we? Balance it, figure out either the left out ball as a normal one or a heavier one. If it's a normal one, we know the group which contains the heavier ball. Put the group with the heavy ball on the scale. It will not balance. Keep replacing until the scale balances and you figure out the heavier ball. Please correct me if I am wrong.
1)put 3 stones each sides
- vinaysachdeva23 November 22, 2010if they are equal then the heavier stone is in the left three stones, otherwise take the three stones of heavier side.
2)Put one on one side and the other on other side. If they are equal, then the left one is the heavier stone otherwise the heavier of the two stones is the required stone.