A server dashboard plots the peak CPU load over a sliding window: for every run of w consecutive samples, it shows the largest one.
Write windowPeaks(loads, w) that returns an array with the maximum of loads[i..i + w - 1] for every start i from 0 to loads.length - w, in order. w is between 1 and loads.length.
Input: loads = [4,2,12,3,8,1,5], w = 3 Output: [12,12,12,8,8]
The windows are [4, 2, 12], [2, 12, 3], [12, 3, 8], [3, 8, 1], and [8, 1, 5].
Input: loads = [7,3], w = 1 Output: [7,3]
With w = 1, each sample is its own window.
1 <= w <= loads.length <= 10^5-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 #387 Busiest Moment per 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.