Measure Milk by Cans Puzzle-Asked in AMTEL interviews.
There is a drum full of milk.
People come for buying milk in the range of 1–40 litres.
You can have only 4 cans to draw milk out of the drum. What should be the measurement of these four cans so that you can measure any amount of milk in the range of 1–40 litres.
Note that the cans cannot be used more than once.
Solution: 1 3 9 27
The right way to think about the solution is that when you have x cans which let you measure all volumes from 1 to N, you now want to include 2*N + 1 as your next can. That way, all weights from N + 1 to 2*N can be measured by subtracting N to 1 ( which we already know how to form using the x cans that we have ) from 2*N + 1. Also, all weights from 2*N + 2 to 3*N + 1 can be formed by adding 1 to N ( which we already know how to form using the x cans that we have ) to 2*N + 1 can.