A status page logs each hour as 1 (the service was up) or 0 (it was down). An engineer can mark at most k down hours as patched, turning them into 1s.
Write longestUptime(hours, k) that returns the length of the longest run of neighboring hours that are all 1 after patching at most k of the 0s.
Input: hours = [1,1,0,0,1,1,1,0,1], k = 1 Output: 5
Patch the 0 at index 7 to get 1, 1, 1, 1, 1 from index 4 to 8.
Input: hours = [0,0,0], k = 0 Output: 0
No patches and no up hours.
0 <= hours.length <= 200000hours[i] is 0 or 1.0 <= k <= hours.lengthRun tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #137 Longest Uptime With k Patches. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.