Try the Problem
You can practice the problem here:
https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/
Problem Description
You are given an integer array bloomDay, where:
represents the day on which the i-th flower blooms.
You are also given two integers:
Rules
To create one bouquet, you must use:
Important constraints:
- A flower can only be used once.
- Only flowers that have already bloomed can be used.
- Flowers must be adjacent in the array.
Your goal is to determine the minimum number of days required so that it becomes possible to create m bouquets.
If it is impossible, return:
Example Walkthrough
Example 1
Input
Output
Explanation
We need:
Garden progress:
Day 1
Bouquets possible = 1
Day 2
Bouquets possible = 2
Day 3
Bouquets possible = 3 ✅
Minimum day = 3
Example 2
Input
Output
Explanation:
We need:
But we only have:
So it is impossible.
Example 3
Input
Output
Explanation:
Day 7
Only 1 bouquet can be made.
Day 12
Now 2 bouquets can be formed.
Minimum day = 12
Constraints
Important observations:
bloomDay[i]can be very large- The array size can be 100,000
- A brute force simulation for every day would be too slow
Thinking About the Problem
At first glance, the problem may look like a simulation problem, where we check the garden day by day.
However, this approach quickly becomes inefficient because the maximum bloom day can be as large as:
So instead of checking every day sequentially, we need to search intelligently for the minimum valid day.
Key Observation
If we wait for more days, more flowers will bloom.
Which means:
This means the function is monotonic.
If it is possible to make m bouquets on day X, then it will also be possible on any day after X.
This type of pattern strongly suggests using:
Binary Search on Answer
Approach: Binary Search on Minimum Day
Instead of checking every day, we search between:
For each candidate day mid:
- Assume we wait until day
mid. - Count how many bouquets we can make.
- If we can make at least m bouquets, try smaller days.
- Otherwise, increase the day.
How We Count Bouquets
While scanning the garden:
- If the flower has bloomed (
bloomDay[i] <= mid) - → increase adjacent flower count
- If a flower has not bloomed yet
- → reset the adjacent counter
Whenever we have:
we form one bouquet.
Your Java Implementation (Binary Search + Greedy Counting)
Dry Run Example
Search range:
Binary search steps:
Try smaller:
Increase day:
Minimum day:
Time Complexity
Binary search runs:
For each check we scan the array:
Total complexity:
Which is efficient for n = 10^5.
Space Complexity
No extra space is required.
Key Takeaway
This problem is a classic example of:
Whenever a problem asks:
Find the minimum value such that a condition becomes true
Binary search is often the best solution.
Conclusion
The Minimum Number of Days to Make m Bouquets problem teaches an important interview technique: transforming a simulation problem into a search problem.
By recognizing the monotonic nature of the problem, we can apply binary search on the answer space and efficiently determine the minimum day required to create the desired number of bouquets.
Mastering problems like this will significantly improve your understanding of binary search patterns, which are extremely common in coding interviews.




