Maximum of every window
Given a list of integers nums and a window size k, slide a window of k consecutive elements from left to right, one position at a time, and return the maximum of each window, in order. The result has len(nums) - k + 1 values.
Constraints: 1 <= k <= len(nums). Aim for O(n): taking max of every window is O(n·k).
Besides the tests, one large input (18,000 numbers, window 9,000) with a ~400 ms limit (scaled to your device's speed): brute force won't pass.
Examples
window_maxima([4,2,7,1,3,6,5], 3)→[7,7,7,6,6]window_maxima([9,8,7,6,5], 2)→[9,8,7,6]window_maxima([1,5,5,1,1,1], 3)→[5,5,5,1]