Skip to main content
Back to problems
#1482
Medium Algorithms

Minimum number of days to make m bouquets

Array Binary Search
56.3% acceptance
Feb 25, 2026
5660
317
You are given an integer array bloomDay, an integer m and an integer k. You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden. The garden consists of n flowers, the ith flower will bloom in the bloomDay[i] and then can be used in exactly one bouquet. 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.

Solution

Rust
Time O(n log n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn min_days(bloom_day: Vec<i32>, m: i32, k: i32) -> i32 {
    let n = bloom_day.len() as i64;
    let (m, k) = (m as i64, k as i64);
    if n < m * k { return -1; }
    let can_make = |day: i32| -> bool {
      let mut bouquets = 0i64;
      let mut streak = 0i64;
      for &b in &bloom_day {
        if b <= day { streak += 1; bouquets += streak / k; streak %= k; }
        else { streak = 0; }
      }
      bouquets >= m
    };
    let (mut lo, mut hi) = (1i32, *bloom_day.iter().max().unwrap());
    while lo < hi {
      let mid = lo + (hi - lo) / 2;
      if can_make(mid) { hi = mid; } else { lo = mid + 1; }
    }
    lo
  }
}