Measuring GALLONS of water | Oracle Interview

You have two jugs, one that holds exactly 3 gallons, and one that holds exactly 5 gallons. Using just these two jugs and a fire hose, how can you measure out exactly 4 gallons of water?

 

 

 

 

 

Solution :

Fill the 5-gallon jug to the top, and then pour it into the 3-gallon
jug until the 3-gallon jug is full. You now have 2 gallons remaining 
in the 5-gallon jug. Pour out the 3-gallon jug, and then pour the 2 
gallons from the 5-gallon jug into the 3-gallon jug. Finally, fill 
the 5-gallon jug to the top and pour it into the 3-gallon jug until 
it's full. Since there was only space left for 1 more gallon in the 
3-gallon jug, you now have exactly 4 gallons in the 5-gallon jug.

Leave a Reply

Your email address will not be published. Required fields are marked *

For Inserting code :
Paste your code in the comment form, select it and then click the language link

C | C++ | Java |

*