483. Minimum Number of Days to Make M Bouquets

MediumBinary SearchBinary Search on AnswerArray

Given bloom days for flowers in a row, you want m bouquets, each needing k adjacent flowers that have all bloomed. Return the minimum number of days to wait, or -1 if it is impossible. Input: '[bloomDay], m, k'.

Input: '[bloomDay], m, k'.

Output: Integer — minimum days, or -1.

Examples

Example 1
Input: [1,10,3,10,2], 3, 1
Output: 3
Explanation: After 3 days, 3 single-flower bouquets are possible.
Example 2
Input: [1,10,3,10,2], 3, 2
Output: -1
Explanation: Need 6 flowers but only 5 exist.
Example 3
Input: [7,7,7,7,12,7,7], 2, 3
Output: 12
Explanation: Adjacent groups of 3.

Constraints

Asked by

FlipkartBloombergAmazonAdobeGoogleMicrosoft
Solve this problem in the editor →