Skip to content

Commit b3483a4

Browse files
committed
2086. Minimum Number of Food Buckets to Feed the Hamsters: RETRY
1 parent 619b910 commit b3483a4

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,3 +1572,4 @@ mod s2079_watering_plants;
15721572
mod s2080_range_frequency_queries;
15731573
mod s2081_sum_of_k_mirror_numbers;
15741574
mod s2085_count_common_words_with_one_occurrence;
1575+
mod s2086_minimum_number_of_food_buckets_to_feed_the_hamsters;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* [2086] Minimum Number of Food Buckets to Feed the Hamsters
3+
*
4+
* You are given a 0-indexed string hamsters where hamsters[i] is either:
5+
*
6+
* 'H' indicating that there is a hamster at index i, or
7+
* '.' indicating that index i is empty.
8+
*
9+
* You will add some number of food buckets at the empty indices in order to feed the hamsters. A hamster can be fed if there is at least one food bucket to its left or to its right. More formally, a hamster at index i can be fed if you place a food bucket at index i - 1 and/or at index i + 1.
10+
* Return the minimum number of food buckets you should place at empty indices to feed all the hamsters or -1 if it is impossible to feed all of them.
11+
*
12+
* Example 1:
13+
* <img alt="" src="https://assets.leetcode.com/uploads/2022/11/01/example1.png" style="width: 482px; height: 162px;" />
14+
* Input: hamsters = "H..H"
15+
* Output: 2
16+
* Explanation: We place two food buckets at indices 1 and 2.
17+
* It can be shown that if we place only one food bucket, one of the hamsters will not be fed.
18+
*
19+
* Example 2:
20+
* <img alt="" src="https://assets.leetcode.com/uploads/2022/11/01/example2.png" style="width: 602px; height: 162px;" />
21+
* Input: hamsters = ".H.H."
22+
* Output: 1
23+
* Explanation: We place one food bucket at index 2.
24+
*
25+
* Example 3:
26+
* <img alt="" src="https://assets.leetcode.com/uploads/2022/11/01/example3.png" style="width: 602px; height: 162px;" />
27+
* Input: hamsters = ".HHH."
28+
* Output: -1
29+
* Explanation: If we place a food bucket at every empty index as shown, the hamster at index 2 will not be able to eat.
30+
*
31+
*
32+
* Constraints:
33+
*
34+
* 1 <= hamsters.length <= 10^5
35+
* hamsters[i] is either'H' or '.'.
36+
*
37+
*/
38+
pub struct Solution {}
39+
40+
// problem: https://leetcode.com/problems/minimum-number-of-food-buckets-to-feed-the-hamsters/
41+
// discuss: https://leetcode.com/problems/minimum-number-of-food-buckets-to-feed-the-hamsters/discuss/?currentPage=1&orderBy=most_votes&query=
42+
43+
// submission codes start here
44+
45+
impl Solution {
46+
pub fn minimum_buckets(hamsters: String) -> i32 {
47+
0
48+
}
49+
}
50+
51+
// submission codes end
52+
53+
#[cfg(test)]
54+
mod tests {
55+
use super::*;
56+
57+
#[test]
58+
#[ignore]
59+
fn test_2086_example_1() {
60+
let hamsters = "H..H".to_string();
61+
62+
let result = 2;
63+
64+
assert_eq!(Solution::minimum_buckets(hamsters), result);
65+
}
66+
67+
#[test]
68+
#[ignore]
69+
fn test_2086_example_2() {
70+
let hamsters = ".H.H.".to_string();
71+
72+
let result = 1;
73+
74+
assert_eq!(Solution::minimum_buckets(hamsters), result);
75+
}
76+
77+
#[test]
78+
#[ignore]
79+
fn test_2086_example_3() {
80+
let hamsters = ".HHH.".to_string();
81+
82+
let result = -1;
83+
84+
assert_eq!(Solution::minimum_buckets(hamsters), result);
85+
}
86+
}

0 commit comments

Comments
 (0)