Amazon Interview Question: Having an infinite supply of ... | Glassdoor

Interview Question

Software Development Engineer Interview

Having an infinite supply of water and two containers, one

  for 3 liters and one for 5 liters, how would you measure 4 liters?
analytical reasoning

Interview Answer

7 Answers


1. Fill and pour 3 liters into the 5 liter container
2. Refill 3 liter container, transfer as much as possible to the 5 liter container
3. Retain the one liter left in the 3 liter container, empty the 5 liter container
4. Transfer the one liter from the 3 liter to the 5 liter container
5. Refill the 3 liter and transfer it to the one liter in the 5 liter container...
5. Fill

RHovey on Jan 17, 2011

That was the exact algorithm I came up with after some 2-3 minutes of thinking (I don't know whether that was rated a good or bad time, but it's interesting to know I'm not the only one who devised it).

My wife, though, took 45 seconds to answer with something I didn't thought in: "have both containers half full". I find it interesting since I NEVER thought of such a simple solution (though more constrained: it relies on the container being somehow regular shaped).

Dario on Jan 17, 2011

Fill 5 and Pour into 3
Empty 3 container and fill left 2ltrs from 5 to 3
Fill 5 and pour into 3 (now u left with 4 ltrs in 5ltr container)

Siva on Jan 18, 2011

This is from the movie Die Hard: With a Vengeance. I'm surprised that anyone would use THIS as a question! All it shows is that you watched the movie!

HTR on Jan 29, 2011

This reminds me an another question:
You've 5ltr & 7ltr container. You've to get 6ltr out of it.

Sathish on Feb 14, 2011

You fill both to the brim and empty half of each. This applies to the 5ltr/7ltr question as well.

David Zeng on Apr 16, 2012

Fill each container halfway, then add the 1.5 liters in the 3 liter bottle to the 2.5 liters in the 5 liter bottle.

LM on Feb 24, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.