Measure Milk by Cans Puzzle-Asked in AMTEL interviews.

Placewit
2 min readFeb 12, 2022

--

Question:

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.

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.

--

--

Placewit
Placewit

Written by Placewit

Upskilling students for tech placements!

No responses yet