365. Water and Jug Problem Medium

@problem@discussion
#Math#Depth-First Search#Breadth-First Search



1/**
2 * [365] Water and Jug Problem
3 *
4 * You are given two jugs with capacities jug1Capacity and jug2Capacity liters. There is an infinite amount of water supply available. Determine whether it is possible to measure exactly targetCapacity liters using these two jugs.
5 * If targetCapacity liters of water are measurable, you must have targetCapacity liters of water contained within one or both buckets by the end.
6 * Operations allowed:
7 * 
8 * 	Fill any of the jugs with water.
9 * 	Empty any of the jugs.
10 * 	Pour water from one jug into another till the other jug is completely full, or the first jug itself is empty.
11 * 
12 *  
13 * Example 1:
14 * 
15 * Input: jug1Capacity = 3, jug2Capacity = 5, targetCapacity = 4
16 * Output: true
17 * Explanation: The famous <a href="https://www.youtube.com/watch?v=BVtQNK_ZUJg&amp;ab_channel=notnek01" target="_blank">Die Hard</a> example 
18 * 
19 * Example 2:
20 * 
21 * Input: jug1Capacity = 2, jug2Capacity = 6, targetCapacity = 5
22 * Output: false
23 * 
24 * Example 3:
25 * 
26 * Input: jug1Capacity = 1, jug2Capacity = 2, targetCapacity = 3
27 * Output: true
28 * 
29 *  
30 * Constraints:
31 * 
32 * 	1 <= jug1Capacity, jug2Capacity, targetCapacity <= 10^6
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/water-and-jug-problem/
38// discuss: https://leetcode.com/problems/water-and-jug-problem/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn can_measure_water(jug1_capacity: i32, jug2_capacity: i32, target_capacity: i32) -> bool {
44        false
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_365() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.