Minimum Number of Days to Make m Bouquets

You are given an integer array bloomDay, an integer m, and an integer k.

You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden.

The garden consists of n flowers. The i^th flower will bloom on bloomDay[i] and then can be used in exactly one bouquet.

Return the minimum number of days you need to wait to be able to make m bouquets from the garden. If it is impossible to make m bouquets, return -1.

Example 1
InputbloomDay = [1,10,3,10,2], m = 3, k = 1
Output3
By day 3, flowers at positions 0, 2, and 4 have bloomed, so three bouquets of one flower each can be made.
Example 2
InputbloomDay = [1,10,3,10,2], m = 3, k = 2
Output-1
Making 3 bouquets with 2 flowers each requires 6 flowers, but the garden only has 5 flowers, so it is impossible.

Constraints

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

Asked at 9 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate