|
| 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