Minimum Number of Days to Make m Bouquets
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 i^th flower will bloom on 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.
Example 1
Input
bloomDay = [1,10,3,10,2], m = 3, k = 1Output
3By day 3, flowers at positions 0, 2, and 4 have bloomed, so three bouquets of one flower each can be made.
Example 2
Input
bloomDay = [1,10,3,10,2], m = 3, k = 2Output
-1Making 3 bouquets with 2 flowers each requires 6 flowers, but the garden only has 5 flowers, so it is impossible.
Constraints
- bloomDay.length == n
- 1 <= n <= 10^5
- 1 <= bloomDay[i] <= 10^9
- 1 <= m <= 10^6
- 1 <= k <= n