Magicsheet logo

Minimum Number of Days to Make m Bouquets

Medium
80.7%
Updated 6/1/2025

Minimum Number of Days to Make m Bouquets

1. What is this problem about?

The Minimum Number of Days to Make m Bouquets coding problem asks you to find the earliest day you can pick enough flowers to satisfy a customer. You have an array bloomDay where each element represents when a flower will bloom. You need to make m bouquets, and each bouquet must consist of k adjacent flowers. Flowers can only be used if they have bloomed by the chosen day.

2. Why is this asked in interviews?

This is a quintessential "Binary Search on Answer" problem, a favorite of Amazon, Microsoft, and Google. It tests if a candidate can recognize that the answer (the number of days) has a monotonic property: if you can make the bouquets on day X, you can definitely make them on day X+1. Identifying this property allows you to solve an optimization problem using a searching algorithm.

3. Algorithmic pattern used

This problem uses the Array, Binary Search interview pattern. Instead of searching through the flowers, you search through the possible days (from 1 to the maximum value in bloomDay). For a chosen day mid, you perform a linear scan of the array to see if you can form m bouquets of k adjacent flowers. If yes, you try a smaller number of days; if no, you need more time.

4. Example explanation

bloomDay = [1, 10, 3, 10, 2], m = 3, k = 1. We need 3 bouquets of 1 flower each.

  • Day 1: [B, ., ., ., .] -> 1 bouquet. Not enough.
  • Day 2: [B, ., ., ., B] -> 2 bouquets. Not enough.
  • Day 3: [B, ., B, ., B] -> 3 bouquets. Success! Answer is 3. If k was 2, we would need 2 adjacent bloomed flowers. On day 10, all flowers bloom, so we'd check then.

5. Common mistakes candidates make

A common error is not checking if the total flowers required (m * k) exceeds the array length immediately—if it does, it's impossible. Another mistake is failing the "adjacent" check logic—candidates often count total bloomed flowers instead of consecutive ones. Finally, choosing the wrong search range for binary search (like 0 to 10^9 instead of min to max of the array) can slightly hurt efficiency.

6. Interview preparation tip

Whenever a problem asks for the "minimum X to satisfy a condition" and the condition becomes easier to satisfy as X increases, always consider Binary Search on the result. It turns a difficult construction problem into a much easier "check if this value works" problem.

Similar Questions