Saturday, June 19, 2010

5 and 3 gallon water containers riddle

It is a problem that is often asked by interviewers to examine the analytical skills of the interviewee. So the problem is that you are provided with 2 water containers with capacity of 5 and 3 gallons. You are asked to come up with 4 gallons of water using only these 2 containers. Nothing else is provided except water which is assumed to be present in large quantity.

When I was asked this question by the interviewer, I quickly thought about dividing both the quantities by 2 and adding them up. Half of 3 is equal to 1.5 and half of 5 is equal to 2.5. Adding these 2 integers gives 4. BINGO!! I was so excited that I figured out the solution in less than 30 seconds. I told the interviewer that you fill both the containers to their maximum capacity and then empty them by half the size of the corresponding containers. Pour the remaining half of water left in 3 gallons containers into the other one and you will have the 4 gallons of water. On that the interviewer replied, "I'm not asking about the approximation, I want exactly 4 gallons of water using the 2 containers". I thought about it for a while and then was finally able to solve the riddle with a small hint from interviewer in the middle.

Here are the steps of solving this riddle:

1)Fill the 5 gallon container completely with water.
2)Pour the water from 5 gallon container into 3 gallon container until it is completely filled. Hence, you are left with 2 gallons in the former container.
3)Empty the 3 gallon water container.
4)Pour the 2 gallon water from 5 gallon container into this one.
5)Again fill the 5 gallon container with water completely.
6)Pour the water into 3 gallon water container until its filled completely.

Since, the 3 gallon container already had 2 gallons of water before, so only 1 gallon of water is being added into it. This means 5 gallon container lost 1 gallon of water. Hence, we are left with 4 gallons of water in the 5 gallon container.