Minimum Number of Days to Make m Bouquets
Expert Answer & Key Takeaways
A complete guide to understanding and implementing Binary Search.
Minimum Number of Days to Make m Bouquets
Return the minimum number of days such that you can make bouquets using adjacent flowers each. Each bouquet must consist of adjacent flowers.
Examples
Input: bloomDay = [1,10,3,10,2], m = 3, k = 1
Output: 3
Approach 1
Level I: Brute Force (Iterate Days)
Intuition
Try every possible day from to . For each day, check if it's possible to form bouquets.
⏱ $O(Range \\cdot N)$💾 $O(1)$
Detailed Dry Run
bloomDay = [1,10,3,10,2], m=3, k=1. Sorted unique days: [1,2,3,10].
Day 1: 1 bouquet. Day 2: 2 bouquets. Day 3: 3 bouquets. Return 3.
Approach 2
Level II: Optimal (Optimization with Sorted Days)
Intuition
Instead of checking every day from 1 to
maxD, only check days where at least one flower blooms. These are the unique values in bloomDay.⏱ $O(N \\log N + N \\cdot \\text{UniqueDays})$💾 $O(N)$
Detailed Dry Run
bloomDay = [1,10,3,10,2], m=3, k=1.
Unique days sorted: [1, 2, 3, 10].
Check 1: 1 (fail), 2: 2 (fail), 3: 3 (pass). Result 3.
Approach 3
Level III: Optimal (Binary Search on Answer)
Intuition
The number of bouquets possible is a monotonic function of days. We can binary search the result in the range .
⏱ $O(N \\log(Max - Min))$💾 $O(1)$
Detailed Dry Run
bloomDay = [1,10,3,10,2], m=3, k=1. Range [1, 10].
- Mid 5: [B, No, B, No, B] -> 3 bouquets. OK, R=5.
- Mid 2: [B, No, No, No, B] -> 2 bouquets. Too few, L=3.
- Mid 3: [B, No, B, No, B] -> 3 bouquets. OK, R=3. Result: 3.
Course4All Technical Board
Verified ExpertSenior Software Engineers & Algorithmic Experts
Our DSA content is authored and reviewed by engineers from top tech firms to ensure optimal time and space complexity analysis.
Pattern: 2026 Ready
Updated: Weekly
Found an issue or have a suggestion?
Help us improve! Report bugs or suggest new features on our Telegram group.