PPractick

DSA interview question

Minimum Days to Make M Bouquets

Medium · Algorithms · Topics: binary search on answer, array

The problem

A florist has a row of flowers, and flower i blooms on day bloomDay[i]. She needs m bouquets, each made from k adjacent bloomed flowers, and each flower can be used only once. What's the earliest day she can make all m bouquets? If there aren't even m × k flowers, it's impossible. Waiting longer can only bloom more flowers, so "can make m bouquets by day d" is monotonic in d. That's binary search on the day, with a linear scan to count bouquets for a given day.

Example: bloomDay = [1, 10, 3, 10, 2], m = 3, k = 1 → 3.

Function signature

int minDays(const vector<int>& bloomDay, long long m, long long k);  // earliest day, or -1

Test cases

Input (bloomDay, m, k)OutputExplanation
([1, 10, 3, 10, 2], 3, 1)3By day 3, flowers 1, 3 and 2 have bloomed
([1, 10, 3, 10, 2], 3, 2)-1Needs 6 flowers but only 5 exist
([7, 7, 7, 7, 12, 7, 7], 2, 3)12On day 7 the flower at index 4 splits the row
([1000000000, 1000000000], 1, 1)1000000000
([1, 10, 2, 9, 3, 8, 4, 7, 5, 6], 4, 2)9

(Confirm: bouquets need k adjacent flowers; each flower is used at most once; m × k can exceed the int range.)

How interviewers phrase it

Clarifying questions to ask

  1. Must the k flowers be adjacent?
  2. What if it's impossible: return -1?
  3. How large are m and k? (Their product can overflow 32 bits.)

Follow-ups to expect

  1. "What's the feasibility check for a day d?"
  2. "Why is greedy counting optimal?"
  3. "What's the search range?"
  4. "When is it impossible?"
  5. "Complexity?"

Practise questions like this with a real engineer

On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.

Book a free mock interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in