A monitoring dashboard samples server load once a minute into loads. Its "peak" chart shows, for every window of k consecutive minutes, the highest load in that window.
Write windowPeaks(loads, k) that returns the peak of each window, from the window starting at minute 0 to the window ending at the last minute. There are loads.length - k + 1 windows.
Input: loads = [2,6,-2,-5,4,1,8,3], k = 3 Output: [6,6,4,4,8,8]
The windows [2, 6, -2], [6, -2, -5], [-2, -5, 4], ... have peaks 6, 6, 4, 4, 8, 8.
Input: loads = [1], k = 1 Output: [1]
One window with one minute.
1 <= k <= loads.length <= 3 * 10^5-10^4 <= loads[i] <= 10^4Run 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 #272 Peak Load per Time Window. 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.