Minimum Number of Days to Make m Bouquets
Updated
Problem statement
You are given an integer array bloomDay and two integers m and k. There are n flowers in a row, and flower i blooms on day bloomDay[i]. Once a flower has bloomed, it stays bloomed and can be used on that day or any later day.
You want to make m bouquets. Each bouquet needs k adjacent flowers that have all bloomed, and each flower can be used in at most one bouquet.
Return the minimum number of days you need to wait before you can make m bouquets. If it is impossible to make m bouquets, return -1.
Function
minDays(bloomDay: int[], m: int, k: int) → intExamples
Example 1
bloomDay = [4,2,9,3,7,5,1]m = 2k = 2return = 5Each bouquet needs 2 adjacent bloomed flowers. By day 4, flowers 0, 1, 3 and 6 have bloomed. Only flowers 0 and 1 are next to each other, so you can make 1 bouquet. On day 5, flower 5 blooms too, so flowers 5 and 6 make a second bouquet. The answer is 5.
Example 2
bloomDay = [6,1,4]m = 2k = 2return = -12 bouquets of 2 flowers need 4 flowers, but there are only 3. It is impossible, so the answer is -1.
Example 3
bloomDay = [2,8,2,8,2]m = 1k = 2return = 8By day 2, flowers 0, 2 and 4 have bloomed, but no two of them are next to each other. On day 8 every flower has bloomed, so flowers 0 and 1 make the bouquet. The answer is 8.
Constraints
bloomDay.length == n1 <= n <= 10^51 <= bloomDay[i] <= 10^91 <= m <= 10^61 <= k <= n
More PhonePe interview questions
- Maximum Sum with K-Element SkippingONSITE INTERVIEW · Seen Dec 2026
- Evaluate DivisionONSITE INTERVIEW · Seen Oct 2026
- K-th Smallest Value in a Sorted MatrixONSITE INTERVIEW · Seen Oct 2026
- Identify Two Failing Tests From an Oracle TranscriptONSITE INTERVIEW · Seen Sep 2026
- Count Bowl SubarraysONSITE INTERVIEW · Seen Jul 2026
- Reconstruct ItineraryONSITE INTERVIEW · Seen Jul 2026
- Constrained Jump SequencesOA · Seen Aug 2026
- Maximum Payout with Context SwitchesOA · Seen Aug 2026
- Substrings Without a Target SubsequenceOA · Seen Aug 2026
- Luna and the Colorful SocksOA · Seen Jul 2026
Similar questions at other companies
- Count Winning Dice Face PairsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Search in a Rotated Sorted ArrayAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions
- 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Smallest Batch Size Within a Step LimitMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Peak of an Increasing-Then-Decreasing ArraySnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
- Online Meeting Scheduler with Fixed RoomsUber · ONSITE INTERVIEWUber interview questions
- Search a 2D MatrixWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
- Search in Rotated Sorted ArrayKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Find First and Last Position in Sorted ArrayPaytm · ONSITE INTERVIEWPaytm interview questions