Window Maximums
Return a list with the maximum of each contiguous window of size k in nums, from left to right.
Requirements
- Run in time using a monotonic deque.
Constraints
Examples
EXAMPLE WALKTHROUGHclassic
A guided view of the published example, not a trace of your code.
INPUT
[[1,3,-1,-3,5,3,6,7],3]TASKwindow_maximums()
EXPECTED OUTPUT
[3,3,5,5,6,7]Start with the input values shown in this example.
Example 1 of 3
Input: nums = [1,3,-1,-3,5,3,6,7], k = 3
Output: [3,3,5,5,6,7]
Explanation: classic
Input: nums = [1], k = 1
Output: [1]
Explanation: single
Input: nums = [9,8,7,6], k = 2
Output: [9,8,7]
Explanation: decreasing
Hint 1
Keep indices in a deque whose values are decreasing.
Hint 2
Drop indices that fall out of the window from the front.