Interview Question

Back-end Software Engineer Interview

-Vancouver, BC

Grow Technologies

You are given a 5L and a 3L jug. Both jugs are really oddly shaped and don't have any measure markings, so you can only fill the jug up to the top. Given unlimited water, can you somehow make 4L of water from these two jugs?

AnswerAdd Tags

Interview Answers

2 Answers

0

This was the Die Hard III problem!

Anonymous on

0

This is a classic question that is in CTCI/CareerCup. There are two solutions for this. 1) Fill up the 5L jug, then pour it into the 3L jug (5L jug has 2L of water in it). Pour out the 3L jug and pour the 5L jug into the 3L jug (3L jug now has 2L in it, 5L jug has 0L). Fill up the 5L jug with water, and pour it into the 3L jug until it is full! (5L jug has 4L in it, 3L jug has 3L in it) 2) Fill up the 3L jug, then pour it into the 5L jug (5L jug has 3L in it, 3L jug has nothing). Fill up the 3L jug again, and pour it into the 5L jug until it is full (5L jug has 5L in it, 3L jug has 1L in it). Pour out the 5L jug, then pour the 3L jug into the 5L jug (5L jug has 1L in it, 3L jug has 0L). Fill the 3L jug and then pour it into the 5L jug (5L jug has 4L in it, 3L jug has 0L).

Anonymous on

Add Answers or Comments

To comment on this, Sign In or Sign Up.