Loading...
Loading...
Loading...
A nursery has n flower beds in a row. Bed i blooms on day bloom[i] and stays in bloom. A bouquet needs size adjacent beds that are all in bloom, and a bed can go into only one bouquet. Print the earliest day on which bouquets bouquets can be made, or -1 if it is impossible.
Example 1
Input
5 2 2 1 10 3 10 2
Output
10
Example 2
Input
7 2 3 7 7 7 12 7 7 7
Output
7
Try the problem first. Open one hint at a time.
If the bouquets can be made on day d, they can also be made on any later day, so the check is monotonic.
For a day, scan the beds: count a run of consecutive bloomed beds, make a bouquet every time the run reaches size, and reset the run at an unbloomed bed.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor