1482. Minimum Number of Days to Make m Bouquets Medium
1/**
2 * [1482] Minimum Number of Days to Make m Bouquets
3 *
4 * You are given an integer array bloomDay, an integer m and an integer k.
5 * You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden.
6 * The garden consists of n flowers, the i^th flower will bloom in the bloomDay[i] and then can be used in exactly one bouquet.
7 * Return the minimum number of days you need to wait to be able to make m bouquets from the garden. If it is impossible to make m bouquets return -1.
8 *
9 * Example 1:
10 *
11 * Input: bloomDay = [1,10,3,10,2], m = 3, k = 1
12 * Output: 3
13 * Explanation: Let us see what happened in the first three days. x means flower bloomed and _ means flower did not bloom in the garden.
14 * We need 3 bouquets each should contain 1 flower.
15 * After day 1: [x, _, _, _, _] // we can only make one bouquet.
16 * After day 2: [x, _, _, _, x] // we can only make two bouquets.
17 * After day 3: [x, _, x, _, x] // we can make 3 bouquets. The answer is 3.
18 *
19 * Example 2:
20 *
21 * Input: bloomDay = [1,10,3,10,2], m = 3, k = 2
22 * Output: -1
23 * Explanation: We need 3 bouquets each has 2 flowers, that means we need 6 flowers. We only have 5 flowers so it is impossible to get the needed bouquets and we return -1.
24 *
25 * Example 3:
26 *
27 * Input: bloomDay = [7,7,7,7,12,7,7], m = 2, k = 3
28 * Output: 12
29 * Explanation: We need 2 bouquets each should have 3 flowers.
30 * Here is the garden after the 7 and 12 days:
31 * After day 7: [x, x, x, x, _, x, x]
32 * We can make one bouquet of the first three flowers that bloomed. We cannot make another bouquet from the last three flowers that bloomed because they are not adjacent.
33 * After day 12: [x, x, x, x, x, x, x]
34 * It is obvious that we can make two bouquets in different ways.
35 *
36 *
37 * Constraints:
38 *
39 * bloomDay.length == n
40 * 1 <= n <= 10^5
41 * 1 <= bloomDay[i] <= 10^9
42 * 1 <= m <= 10^6
43 * 1 <= k <= n
44 *
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/
49// discuss: https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54 pub fn min_days(bloom_day: Vec<i32>, m: i32, k: i32) -> i32 {
55 0
56 }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_1482() {
67 }
68}
69
Back
© 2025 bowen.ge All Rights Reserved.