Loading...
Loading...
You are given a list of integers readyDay and two integers m and k. A parking lot has n spaces in a row, and every space is being repaved. readyDay[i] is the day on which space i is finished. Once a space is finished, it stays finished.
There are m buses to park in the lot. Each bus takes up exactly k consecutive spaces, and every one of those spaces must be finished. No two buses can share a space.
Return the earliest day on which all m buses can be parked at the same time. If there's no solution, return -1. This happens exactly when the lot has fewer than m * k spaces.
Input: readyDay = [1,10,3,10,2], m = 3, k = 1
Output: 3
Explanation: With k = 1, each bus needs a single finished space, so 3 finished spaces are needed. On day 1 only space 0 is finished. On day 2 spaces 0 and 4 are finished. On day 3 spaces 0, 2, and 4 are finished, so day 3 is the first day all 3 buses can park.
Input: readyDay = [1,10,3,10,2], m = 3, k = 2
Output: -1
Explanation: 3 buses of 2 spaces each need 6 spaces in total, but the lot only has 5, so no day can ever work.
Input: readyDay = [7,7,7,7,12,7,7], m = 2, k = 3
Output: 12
Explanation: Each bus needs 3 consecutive finished spaces. On day 7 every space except space 4 is finished, so the finished spaces form the runs [0, 1, 2, 3] and [5, 6]. The first run fits one bus and the second run has only 2 spaces, so only 1 bus can park. On day 12 every space is finished, and spaces [0, 1, 2] and [3, 4, 5] hold 2 buses.
n == readyDay.lengthreadyDay[i] ≤109