DSA Tracker

Medium

Minimum Days to Make M Bouquets

A medium Binary Search problem included in Striver A2Z. Below: the roles whose interviews prioritise this topic, and how to practise it.

Topic
Binary Search
Sheets
1
Core for
7 roles
Platform
LeetCode

The problem

You have a garden with n flowers, each blooming on a specific day. Given a bloomDay array and integers m and k, you need to make m bouquets. Each bouquet requires k adjacent blooming flowers. Return the minimum number of days you must wait to make m bouquets. If impossible, return -1.

Example 1

Input
bloomDay = [1,10,3,10,2], m = 3, k = 1
Output
3
Why
On day 3, flowers 1, 3, and 4 have bloomed, allowing 3 bouquets each with 1 flower.

Example 2

Input
bloomDay = [1,10,3,10,2], m = 3, k = 2
Output
-1
Why
We need 6 flowers total (3 bouquets * 2 each) but only have 5 flowers, so it is impossible.

Example 3

Input
bloomDay = [7,7,7,7,12,7,7], m = 2, k = 3
Output
12
Why
On day 12, all flowers have bloomed and we can make 2 bouquets of 3 adjacent flowers each.

Constraints

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

How to think about it

Updated 2026-09-09

The count of bloom flowers never shrinks over time. If you can assemble m bouquets on day D, you can also assemble them on any day later than D. The feasibility predicate is purely monotonic over the timeline, making day D searchable via binary search.

Approaches, worst first

  1. Day by day check

    time O((max - min) * n) · space O(1)

    Increment day candidate from min(bloomDay) to max(bloomDay) and run a linear check for adjacent flowers. Far too slow when bloom days reach 10^9.

  2. Binary search on bloom daysWrite this one

    time O(n log(max - min)) · space O(1)

    Search days between min(bloomDay) and max(bloomDay). On any candidate day, walk the flowers greedily counting contiguous bloomed flowers, incrementing bouquets whenever consecutive count hits k and resetting on unbloomed flowers.

Where people lose marks · 3
  • Integer overflow during impossibility check if m * k is calculated in 32-bit signed integers; when m = 10^6 and k = 10^5, m * k reaches 10^11 and exceeds 32-bit limits.
  • Carrying adjacent bloomed flower counters across unbloomed flower gaps; the counter must reset to zero immediately upon encountering a flower whose bloom day exceeds mid.
  • Missing the quick-exit check where total flowers n < m * k, where no valid allocation can ever succeed.

The theory behind it

Binary Search — the ground this problem stands on. All Binary Search problems

What Binary Search is

Binary search is the guessing strategy used when searching a thick telephone directory or guessing a secret number between one and a hundred. Rather than inspecting names one by one from the first page, the search opens straight to the middle page. If the target precedes that middle entry, the entire back half is discarded; if it follows, the front half is eliminated. Repeating this halved split finds the item with remarkable speed.

When to reach for it

Reach for binary search when queries target sorted collections, rotated sorted arrays, or monotonic answer spaces. Strong hints include logarithmic time constraints like O(log n) or search ranges exceeding one billion where stepping one value at a time times out. It also applies when validating whether a guessed solution is possible via a monotonic boolean check, known as binary search on answer.

How the pattern works

Define the search territory with two inclusive pointers, low and high. Compute the midpoint using low plus half the difference to high, avoiding integer overflow. Formulate an exact boolean condition that divides the range into true and false halves. Decide whether the boundary condition includes the midpoint or shifts strictly past it. The loop invariant states that the sought target, if it exists, remains trapped inside the interval throughout every iteration.

What each operation costs

OperationTime
find target in sorted arrayO(log n)
find boundary in monotonic rangeO(log n)
What usually goes wrong with Binary Search
  • Triggering integer overflow by computing middle using low plus high divided by two instead of low plus half of high minus low in fixed-width numeric types.
  • Creating an infinite loop when the interval shrinks to two elements by setting low equal to mid when mid was rounded down.
  • Mismatched loop condition and bounds updates, such as pairing low less than or equal to high with non-advancing pointer assignments that never terminate.

Which roles need this problem

Binary Search is a core topic for these 7 roles — if you're targeting one of them, this problem is early in your path, not optional.

Secondary for 17 more roles, including Full-Stack Developer, Data Engineer, Android Developer.

Track this in your role's order

Pick your target role and all 370 problems — including this one — resequence to what that interview actually asks. Free.

Start free

More Binary Search problems

Problem set and role mapping as of .