Minimum Number of Days to Make m Bouquets
MediumBinary Search
Decode it first. Clues, constraints, pattern and plan before any code.Flower i in a garden blooms on day bloom_day[i] and stays bloomed. A bouquet needs k adjacent bloomed flowers, and each flower can go into at most one bouquet. Return the minimum number of days to wait before you can make m bouquets, or -1 if it is impossible.
bloom_day = [1, 10, 3, 10, 2], m = 3, k = 1 → 3
bloom_day = [1, 10, 3, 10, 2], m = 3, k = 2 → -1 (needs 6 flowers, only 5 exist)
bloom_day = [7, 7, 7, 7, 12, 7, 7], m = 2, k = 3 → 12Constraints
1 <= bloom_day.length <= 10^51 <= bloom_day[i] <= 10^91 <= m <= 10^61 <= k <= bloom_day.length