Binary Search Searching the answer
246. Minimum Number of Days to Make m Bouquets
A garden has a row of flowers. Flower i opens on day bloomDay[i] and stays open from then on, so on any day
d the open flowers are those with bloomDay[i] ≤ d.
You want to make m bouquets. Each bouquet takes k open flowers that stand next to each other in the row.
A flower can go into only one bouquet, and flowers left over are fine.
Return the earliest day on which you can make all m bouquets. If the garden can never give that many, return
-1.
Example 1
Input: bloomDay = [4, 9, 2, 7, 3, 8, 5], m = 2, k = 2
8Explanation: On day 8 every flower except flower 1 is open. Flowers 2 to 6 stand together, so they make two bouquets: flowers 2 and 3, and flowers 4 and 5. On day 7 flower 5 is still closed, and only one bouquet fits.
Example 2
Input: bloomDay = [1, 1, 1, 1, 1], m = 3, k = 2
-1Explanation: Three bouquets of two need six flowers, and the garden has only five.
Example 3
Input: bloomDay = [10, 1000000000, 10, 10], m = 2, k = 2
1000000000Explanation: Two bouquets of two use all four flowers, so we must wait for flower 1, which opens on day 1000000000.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ bloomDay.length ≤ 1051 ≤ bloomDay[i] ≤ 1091 ≤ m ≤ 1061 ≤ k ≤ 106
Clarifying questions
What you would ask an interviewer before writing any code.