Minimum Number of Days to Make m Bouquets - Problem
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.
Input & Output
Example 1 — Basic Case
$
Input:
bloomDay = [1,10,3,10,2], m = 3, k = 1
›
Output:
3
💡 Note:
By day 3, flowers at indices 0, 2, and 4 have bloomed (bloom days 1, 3, 2). Each bouquet needs k=1 adjacent flower, so we can make 3 bouquets from positions [0], [2], [4].
Example 2 — Adjacent Required
$
Input:
bloomDay = [1,10,3,10,2], m = 2, k = 2
›
Output:
-1
💡 Note:
We need 2 bouquets with k=2 adjacent flowers each (total 4 flowers). But we only have 5 flowers total, and they never form 2 groups of 2 adjacent bloomed flowers simultaneously.
Example 3 — Later Day Needed
$
Input:
bloomDay = [7,7,7,7,12,7,7], m = 2, k = 3
›
Output:
12
💡 Note:
By day 7, all flowers except index 4 have bloomed. We need 2 groups of 3 adjacent flowers. Only by day 12 when all flowers bloom can we make groups [0,1,2] and [4,5,6].
Constraints
- 1 ≤ bloomDay.length ≤ 105
- 1 ≤ bloomDay[i] ≤ 109
- 1 ≤ m, k ≤ bloomDay.length
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array of bloom days, m bouquets needed, k adjacent flowers per bouquet
2
Process
Find minimum day when m groups of k adjacent bloomed flowers exist
3
Output
Minimum number of days to wait, or -1 if impossible
Key Takeaway
🎯 Key Insight: Binary search on the answer space (days) is much more efficient than checking every day sequentially
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code