Cracking The Coding Interview/Q 6.1
From Software Engineers Wiki
You have 20 bottles of pills. 19 bottles have 1.0 gram pills, but one has pills of weight 1.1 grams. Given a scale that provides an exact measurement, how would you find the heavy bottle? You can only use the scale once.
- Assign unique number from 1 to 20 to each bottle.
- From a bottle number N, take N number of pills.
- Weight all the pills once.
- If all pills weighted 1.0 gram, they would weight 210 grams. If the bottle N has 1.1 gram pills, it will weight 210 + N * 0.1 grams.