Sliding Window Maximum

Hard

Given nums and a window size k, return the maximum of every window as it slides from left to right.

Example 1

maxSlidingWindow()
Input
nums = [1,3,-1,-3,5,3,6,7], k = 3
Output
[3,3,5,5,6,7]

Example 2

maxSlidingWindow()
Input
nums = [1], k = 1
Output
[1]
Constraints
1 <= nums.length <= 10^5
1 <= k <= nums.length
-10^4 <= nums[i] <= 10^4

Topics

ArraysSliding WindowDequeMonotonic Queue

Implement maxSlidingWindow in the editor and return the answer — printing it is never graded.