Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

3 Jugs Puzzle
INTERVIEWPUZZLE

3 Jugs Puzzle

Solve the classic jug-measuring puzzle by transferring water between containers with limited capacities.

The Puzzle: You have a 3-litre jug, a 5-litre jug, and an unlimited supply of water. How can you measure exactly 4 litres of water?

1. The Methodical Approach

There are usually two ways to solve these: starting with the small jug or starting with the large jug.

Solution A: Start with 5L Jug

  1. Fill the 5L jug. (5L in 5-jug, 0L in 3-jug)
  2. Pour 5L into 3L jug. (2L in 5-jug, 3L in 3-jug)
  3. Empty 3L jug. (2L in 5-jug, 0L in 3-jug)
  4. Pour the 2L from 5L into 3L jug. (0L in 5-jug, 2L in 3-jug)
  5. Fill the 5L jug again. (5L in 5-jug, 2L in 3-jug)
  6. Pour from 5L into 3L jug until full. (The 3L jug only has 1L of space left).
  7. Result: You have 4 Litres remaining in the 5L jug!

Interview-Focused Questions

Q: Can you measure ANY amount using two jugs of size A and B?

A: No. You can only measure amounts that are multiples of the Greatest Common Divisor (GCD) of A and B. For example, with a 6L and 3L jug, you can only measure 3 and 6, never 4.

Q: Is there a faster way?

A: You can also start by filling the 3L jug first. In many cases, one path is shorter than the other. In a Die Hard movie version of this puzzle, efficiency was a matter of life and death!

Summary Formula

The state of the jugs can be represented as (x,y)(x, y). You are basically solving the equation 5x+3y=45x + 3y = 4 for integers xx and yy.

My Private Notes

Notes are auto-saved locally to this device.