Code Room
CodingMediumcod-g166
Subject Gcd lcmLevel Mid–Senior~20 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

You have two jugs with capacities jug1 and jug2 liters (non-negative integers). You may fill a jug completely, empty a jug, or pour from one jug into the other until either the source is empty or the destination is full. Return True if it is possible to measure exactly target liters of water in total across the two jugs, otherwise False. Capacities and target are at most 10^9.

Implement
water_jug_reachable(jug1: int, jug2: int, target: int) → bool
Examples
in[3,5,4]outtrue
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.