Ctrl K

Earliest Day for the Bouquets

Medium
Flowers grow in a single row; flower i opens on day bloom[i] and stays open after that. You need bouquets bouquets, each made of exactly size flowers that stand next to each other. A flower can go into only one bouquet. Return the earliest day by which all the bouquets can be made, or -1 if that never happens.
Example 1
bloom=[5, 2, 2, 8, 3, 3], bouquets=2, size=2 → 3

By day 3 flowers 2, 3, 5 and 6 (counting from one) are open: pairs 2–3 and 5–6 make two bouquets.

Example 2
bloom=[4, 4, 4], bouquets=2, size=2 → -1

Two bouquets of two need four flowers, but only three grow.

Example 3
bloom=[1, 9, 1, 1], bouquets=1, size=3 → 9

Three neighbouring open flowers exist only from day 9: flowers 2–4.

Constraints
  • 1 ≤ len(bloom) ≤ 10⁵
  • 1 ≤ bloom[i] ≤ 10⁹
  • 1 ≤ bouquets ≤ 10⁶
  • 1 ≤ size ≤ len(bloom)
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFind in a Shifted Sorted Array MediumFirst and Last Copy MediumFind in a Row-Chained Grid MediumFind in a Shifted Array With Repeats MediumMinimum of a Shifted List Medium
loading Python…
Input
bloom=[5, 2, 2, 8, 3, 3], bouquets=2, size=2
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 96 tests on the server, hidden ones included.