Minimum Number of Days to Make m Bouquets
Real-world version: Solar String CommissioningThe statement here is our own: the same inputs, outputs and technique.
A solar field is built as one long row of panels. readyDay[i] is the day panel i is energised; the panel carries nothing before that day and stays energised from that day onwards.
The field is commissioned in strings. A string is k panels that sit next to each other in the row and are all energised, and a panel may be wired into at most one string.
Return the earliest day on which m strings can be picked out of the row at once. If the row can never supply m strings, return -1. Every readyDay[i] is at least 1, so -1 cannot be confused with a real day.
Examples
Example 1
- Input
- readyDay = [4, 1, 5, 1, 4, 4], m = 2, k = 2
- Output
- 4
On day 4 the only panel still dark is panel 2, so panels 0 and 1 make one string and panels 3 and 4 make the other, leaving panel 5 spare.
Example 2
- Input
- readyDay = [1, 8, 2, 2, 6], m = 1, k = 2
- Output
- 2
Panels 2 and 3 are both energised on day 2 and sit next to each other, which is the one string the field asks for.
Example 3
- Input
- readyDay = [2, 3], m = 2, k = 2
- Output
- -1
Two strings of two panels would take four panels in all and the row holds only two, so no day supplies them.
Constraints
- readyDay.length == n
- 1 <= n <= 10^5
- 1 <= readyDay[i] <= 10^9
- 1 <= m <= 10^6
- 1 <= k <= n
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def earliest_commission_day(readyDay: list[int], m: int, k: int) -> int:public int earliestCommissionDay(int[] readyDay, int m, int k)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 13 test cases: 13 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's