MEDIUMasked at 3 companies

Water and Jug Problem

A medium-tier problem at 43% community acceptance, tagged with Math, Depth-First Search, Breadth-First Search. Reported in interviews at Wells Fargo and 2 others.

Founder's read

Water and Jug Problem is a deceptively simple-sounding medium that appears in screens at Uber, Lyft, and Wells Fargo. The setup feels like a puzzle: you have two jugs of unknown capacity, unlimited water, and need to measure an exact amount. Most candidates approach it as a simulation problem, running BFS or DFS to explore states. The trap is spending 20 minutes coding graph traversal when the real solution is a single math insight. With only 43% acceptance, this one separates people who've seen the pattern from people who grind it out. If you hit this live and blank, StealthCoder solves it in seconds while the proctor sees nothing.

Companies asking
3
Difficulty
MEDIUM
Acceptance
43%

Companies that ask "Water and Jug Problem"

If this hits your live OA

Water and Jug Problem is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The brute-force approach is BFS or DFS: model each jug state as a node, pour water between jugs as edges, search until you reach the target. It works, but it's slow and verbose. The actual trick is Bezout's identity from number theory: you can measure a volume V using two jugs of capacity X and Y if and only if V is a multiple of GCD(X, Y). The problem collapses to a math check, not a graph search. Candidates who don't know this either waste time coding a full state-space explorer or get stuck thinking the problem is unsolvable. The topics list confirms both approaches are tested: DFS and BFS are red herrings. When you walk into the OA and see this, the math path is the hedge. StealthCoder knows which approach lands you in the right 43%.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Water and Jug Problem recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Water and Jug Problem interview FAQ

Is this really a medium or am I bad at it?+

It's genuinely a medium with a 43% acceptance rate. The median candidate tries BFS/DFS and times out or hits TLE. The people who pass either know the GCD trick or reverse-engineer it under pressure. You're not bad; the problem is just asymmetric: five minutes if you know the pattern, thirty if you don't.

Do Uber and Lyft actually ask this?+

Yes. Both appear in the top companies list for this problem. Lyft and Uber love math-based problems disguised as simulation problems. If you're interviewing there, knowing the Bezout's identity shortcut is a real edge.

Should I code the BFS solution or memorize the math trick?+

Memorize the trick. The math is one line: return (target % gcd(x, y)) == 0 and target <= x + y. The BFS approach is defensive but expensive. In a live OA, the math gets you done in 90 seconds. The graph search gets you a TLE or a long debug session.

What's the trick I'm missing?+

Bezout's identity: you can measure a volume V using jugs X and Y if V is a multiple of GCD(X, Y) and V is not larger than X plus Y. The problem isn't about simulating pours; it's about divisibility. Once you know that, the entire problem flips from hard to trivial.

If I don't know the math, will the graph search pass?+

Maybe on small inputs. BFS/DFS will time out or hit memory limits on large test cases. The problem is designed to fail brute-force approaches. If you're prepping for Uber or Lyft, the math shortcut is mandatory, not optional.

Want the actual problem statement? View "Water and Jug Problem" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.