Skip to content
Decoder

Minimum Number of Days to Make m Bouquets

Medium

Problem

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.

Example 1

Input
bloom_day = [1, 10, 3, 10, 2], m = 3, k = 1
Output
3

Example 2

Input
bloom_day = [1, 10, 3, 10, 2], m = 3, k = 2
Output
-1
Why
needs 6 flowers, only 5 exist

Example 3

Input
bloom_day = [7, 7, 7, 7, 12, 7, 7], m = 2, k = 3
Output
12

Constraints

  • 1 <= bloom_day.length <= 10^5
  • 1 <= bloom_day[i] <= 10^9
  • 1 <= m <= 10^6
  • 1 <= k <= bloom_day.length

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.