DSA interview question
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.
int minDays(const vector<int>& bloomDay, long long m, long long k); // earliest day, or -1
Input (bloomDay, m, k) | Output | Explanation |
|---|---|---|
([1, 10, 3, 10, 2], 3, 1) | 3 | By day 3, flowers 1, 3 and 2 have bloomed |
([1, 10, 3, 10, 2], 3, 2) | -1 | Needs 6 flowers but only 5 exist |
([7, 7, 7, 7, 12, 7, 7], 2, 3) | 12 | On 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.)
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 interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in