All problems
0264MediumArrayBinary Search

Solar String Commissioning

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1482Minimum Number of Days to Make m Bouquets

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def earliest_commission_day(readyDay: list[int], m: int, k: int) -> int:
Java
public int earliestCommissionDay(int[] readyDay, int m, int k)
September 7
Apply