Code RoomWater jug measurement
MediumPrep Room Coding #741

Water jug measurement

CodingAlgorithms & data structuresMid–Senior~20 min

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.

0:00 of about 20 min
InputExpectedGot
[3,5,4]truenot run yetsample