A window of size k slides from the left end of nums to the right end, one position at a time. Return the maximum value in each window position: a list of len(nums) - k + 1 values.
For nums = [1, 3, -1, -3, 5, 3, 6, 7] and k = 3 the answer is [3, 3, 5, 5, 6, 7].
The starter code scans every window. It is correct but too slow when k is large.
Example 1
Input:
sliding_window_max([1, 3, -1, -3, 5, 3, 6, 7], 3)
Output:
[3, 3, 5, 5, 6, 7]
Example 2
Input:
sliding_window_max([1], 1)
Output:
[1]
1 <= k <= len(nums) <= 200000-10**9 <= nums[i] <= 10**9No results yet
Run your code to check it against the examples, or submit to run every test.