Solution: Water and Jug Problem
Understand how to solve the water and jug problem by applying Bézout's Identity and the greatest common divisor (GCD). This lesson helps you determine if a target liter amount is achievable using two jugs through efficient mathematical checks without simulation. You will learn the conditions for measuring exact amounts and analyze the solution's time and space complexity.
We'll cover the following...
Statement
You are given two jugs with capacities of x liters and y liters, respectively, along with an infinite water supply. Determine whether it is possible for the total amount of water in both jugs may reach target liters.
You may perform the following operations any number of times:
Fill either jug completely with water.
Empty either jug completely.
Pour water from one jug into the other until either the receiving jug becomes ...