
Asked in Oyo Rooms
Water Jug Problem Statement
You have two water jugs with capacities X
and Y
liters respectively, both initially empty. You also have an infinite water supply. The goal is to determine if it is possible to measure exactly Z
liters using these two jugs and the operations outlined below.
Operations Allowed:
• Fill any of the jugs completely with water.
• Empty any of the jugs.
• Pour water from one jug into another until the other jug is full or the first jug is empty.
Input:
The input consists of multiple test cases. The first line contains an integer 'T' representing the number of test cases. The next T lines each contain three space-separated integers X, Y, and Z indicating the capacities of both jugs and the target measurement, respectively.
Output:
For each test case, output 'True' if it's possible to measure exactly Z liters, otherwise output 'False'. Each result should be on a new line.
Example:
To measure 2 liters using jugs with capacities 4 and 6 liters:
- Fill the 6-liter jug completely.
- Transfer from the 6-liter jug to the 4-liter jug until the latter is full.
- Repeat the transfer from the 6-liter jug to the 4-liter jug.
Constraints:
1 ≤ T ≤ 5 * 104
0 ≤ X, Y, Z ≤ 5 * 104
- Time Limit: 1 second
Note:
You do not need to print anything; the printing is handled externally. Simply implement the required function.

AnswerBot
4mo
The Water Jug Problem involves determining if a specific amount of water can be measured using two jugs of different capacities.
Start by considering the constraints and limitations of the problem.
Thin...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at Oyo Rooms
Q. Given the head of a singly linked list and two integers m and n, reverse the nod...read more
Q. Merge sort algorithm and divide array in the chunks
Q. Position of Right Most Set Bit Determine the position of the rightmost set bit i...read more
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Oyo Rooms Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

