Loading...
An array readyDay gives, for each of n items arranged in a row, the day on which that item becomes ready.
You must form m groups, each consisting of exactly k adjacent items. An item can be used in at most one group, and a group can only be formed once all k of its items are ready.
Return the earliest day on which m such groups can be formed. If it is impossible (there are fewer than m * k items), return -1.
Input: readyDay = [1,10,3,10,2], m = 3, k = 1
Output: 3
Explanation: Groups of size 1 need three ready items. On day 3 the items with readyDay 1, 2, and 3 are ready.
Input: readyDay = [1,10,3,10,2], m = 3, k = 2
Output: -1
Explanation: Three groups of two need 6 items, but only 5 exist.
Input: readyDay = [7,7,7,7,12,7,7], m = 2, k = 3
Output: 12
Explanation: On day 7 only one group of three adjacent ready items fits (the item at index 4 splits the row). Waiting until day 12 allows two disjoint groups.
n == readyDay.lengthreadyDay[i] ≤109Click "Run" to test with sample cases or "Submit" to run all tests.