Skip to content

Practice Water and Jug Problem

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#365
LeetCode Problem

Water and Jug Problem

Problem Statement

Two jugs have capacities x and y and an unlimited water supply is available. In one step, fill either jug completely, empty either jug, or pour from one jug into the other until the source is empty or the destination is full. Return whether these operations can leave a total of target litres across the two jugs.

Source: Water and Jug Problem on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
x = 3, y = 5, target = 4
Output
true

# Example 2

Input
x = 2, y = 6, target = 5
Output
false

# Example 3

Input
x = 1, y = 2, target = 3
Output
true

Constraints

1 <= x, y, target <= 10^3

Related LeetCode Problems

Practice more problems similar to Water and Jug Problem.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.