Skip to main content
Back to problems
Leetcode
Medium
Arrays
Binary Search
Google
Minimum Number Of Days To Make M Bouquets

Find the minimum day when it becomes possible to make exactly or at least mm bouquets, each requiring kk adjacent bloomed flowers.

Acceptance 0%
Problem Statement

Problem

You are given an array bloomDay, where bloomDay[i] is the day the flower at index i blooms.

A bouquet can be made only from kk adjacent flowers that have all bloomed by the same day.

Your task is to determine the minimum day on which it is possible to make mm bouquets. If it is impossible to make that many bouquets, return -1.

A flower can be used in at most one bouquet.

Intuition

For a fixed day, you can check whether enough bouquets can be formed from consecutive bloomed flowers. The key is that this feasibility test is monotonic with respect to the day, which makes the problem a good fit for binary search on the answer.

Input Format

  • An integer array bloomDay
  • Two integers m and k

Output Format

  • Return the minimum day as an integer
  • Return -1 if making m bouquets is impossible

Constraints

  • Each bouquet needs exactly k adjacent flowers
  • A flower may belong to at most one bouquet
  • If m * k > bloomDay.length, the answer is -1
  • The answer is the smallest day d such that at least m bouquets can be formed using flowers with bloom day <= d
Examples
Sample cases returned by the problem API.

Example 1

Input

bloomDay = [1,10,3,10,2], m = 3, k = 1

Output

3

Explanation

By day 3, flowers at indices 0, 2, and 4 have bloomed, so 3 bouquets of size 1 can be made.

Example 2

Input

bloomDay = [1,10,3,10,2], m = 3, k = 2

Output

-1

Explanation

There are only 5 flowers total, but 3 bouquets of 2 flowers each require 6 flowers.

Show 1 more example

Example 3

Input

bloomDay = [7,7,7,7,12,7,7], m = 2, k = 3

Output

12

Explanation

By day 7, only one bouquet of 3 adjacent bloomed flowers can be formed. By day 12, all flowers are bloomed, allowing two bouquets.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.