#365
Water and Jug Problem
medium · 45% accepted · 1,677 likes · top 28%
math · depth-first search · breadth-first search
Description
You are given two jugs with capacities x liters and y liters. You have an infinite water supply. Return whether the total amount of water in both jugs may reach target using the following operations:
- Fill either jug completely with water.
- Completely empty either jug.
- Pour water from one jug into another until the receiving jug is full, or the transferring jug is empty.
Solution