A monitoring chart shows CPU load samples in loads. Each point of its "peak" line is the highest load among k samples in a row.
Write windowPeaks(loads, k) that returns the maximum of every window of k consecutive samples, from the first window to the last. k is never more than loads.length. Aim for O(n) time, so the answer stays fast for big k.
Input: loads = [2,6,-2,-5,4,1,8,3], k = 3 Output: [6,6,4,4,8,8]
For example the window [-2, -5, 4] peaks at 4.
Input: loads = [4,2], k = 1 Output: [4,2]
With k = 1 each sample is its own window.
1 <= k <= loads.length <= 100000-10^4 <= loads[i] <= 10^4Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #134 Peak Load in Every 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.