Loading…
Loading…
Charting your lesson…
Opening your lesson…
Measuring & Pouring Puzzles
Lesson 2 of 3
6 steps•about 11 min•10 flashcards
Step 1/ 61 min
"You have a 3-litre and a 5-litre jug — measure exactly 4 litres." Water-jug and measuring puzzles are interview staples because they have a clean, teachable method and reward systematic search over guessing. Once you see them as a state-space you can traverse with a few fixed operations, they stop being tricky and become almost mechanical.
What this covers / why it matters: the technique for jug/measuring puzzles — the allowed operations and how to search states — with a fully worked classic. It's a recurring, learnable puzzle type.
Step 2/ 61 min
With two jugs there are only ever a handful of moves, and every solution is a sequence of them:
Rather than guessing, pick one jug to repeatedly fill and pour into the other; the remainders you're forced to leave behind generate the measurable amounts. Two reliable strategies:
You can measure a target T with jugs of size a and b if and only if T is a multiple of gcd(a, b) and T is at most max(a, b). For 3 and 5, gcd is 1, so every whole number up to 5 is measurable — that's why these puzzles are solvable. Knowing this lets you immediately tell an interviewer whether a target is even possible (e.g. with 4- and 6-litre jugs, gcd is 2, so you can never measure an odd amount like 5).
Step 3/ 61 min
"Measure exactly 4 litres using a 3-litre and a 5-litre jug."
Tracking states as (3-jug, 5-jug), using fill-big-pour-into-small:
"I searched by always filling the big jug and topping up the small one; the amount stranded in the big jug walked through 2, then 4 — the target. Since gcd(3,5) = 1, I knew 4 had to be reachable."
Step 4/ 61 min
Step 5/ 61 min
Pouring haphazardly without tracking the state of each jug, then losing the thread and starting over. These puzzles are a small, finite state search — write the (A, B) amounts after every move and commit to one strategy (e.g. fill-big, pour-into-small). Systematic beats lucky, and you can always narrate exactly where you are.
Step 6/ 6· Worked examples1 min
Problem/Question: You have a 3-litre jug and a 5-litre jug and an unlimited water supply. Measure exactly 4 litres.
Solution/Model answer: Work by filling, emptying and transferring between jugs; track the state as (3L jug, 5L jug).
Recall
Keep this
The water-jug family ("measure 4 litres with a 5L and 3L jug") tests systematic search and arithmetic reasoning. The trick is to treat it as reachable combinations rather than guessing — any amount that's a multiple of the GCD of the jug sizes is achievable.
Example (5L, 3L → 4L): fill 5, pour into 3 (leaves 2), empty 3, pour the 2 in, fill 5, top up the 3 (uses 1) → 4 left in the 5L jug.
Expected pattern: A staple reasoning puzzle; interviewers watch for a systematic method and the gcd insight.
Quick recap: Reachable iff target is a multiple of gcd(a,b). Fill-and-pour systematically, track (A,B) state, narrate. Guessing loops forever.
You've read 0 of 6 steps
Now lock it in — questions straight after reading are what make it stick.