Water Jug
Reported by candidates from Cisco's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Cisco asked candidates to solve the Water Jug problem in October 2024, and it's a classic that trips up engineers who overthink the state space. You have two jugs of different capacities and need to measure out a target volume by filling, emptying, and pouring between them. The trick isn't brute force search. It's recognizing this is a math problem hidden in a simulation shell. StealthCoder can feed you the pattern in real time if you blank on the GCD relationship during the OA.
Pattern and pitfall
The Water Jug problem reduces to Bezout's identity: you can measure volume X using jugs of size A and B only if X is a multiple of gcd(A, B). Candidates often code up BFS to explore all reachable states, which works but obscures the insight. The real move is to check if the target divides evenly into the GCD, then backtrack through the jug operations (fill, empty, pour) to construct the sequence. Simulation via BFS is safer for the OA if you're unsure of the math. Most candidates waste time on edge cases: target equals jug size, target is zero, one jug is zero-capacity. StealthCoder bridges the gap between the mathematical insight and clean code if nerves hit during the live assessment.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Water Jug cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Cisco's OA.
Cisco reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Water Jug FAQ
Is this really a math problem or a graph search?+
Both. The math (GCD) tells you if a solution exists. BFS on states (jug1, jug2) finds the sequence. Most engineers code the BFS first and never touch Bezout's identity. That's fine. It passes. The math insight is a hedge if you're stuck.
What's the most common mistake on Cisco's version?+
Not handling edge cases: target equals one of the jug sizes, target is zero, or target is larger than both jugs. Also, mixing up the direction of the pour (A to B vs. B to A). Code defensively and trace through two small examples by hand before submitting.
How long should the solution be?+
BFS solution is 30-50 lines if you're clean about state transitions. Math-first solution is shorter but requires confidence in number theory. Either works. The OA cares about correctness and handling edge cases, not elegance.
Is this still asked in October 2024?+
Yes. It's been asked for years and Cisco reported it recently. It's a stalwart because it has a sting in the tail: simple premise, deceptive depth. Expect it if Cisco is on your list.
Can I solve this in 48 hours of prep if I've never seen it?+
Absolutely. Code up a BFS solution tracing states and jug operations. Test on small examples. If you understand why gcd(A, B) matters, even better. You don't need number theory to pass. Simulation works.