Sliding Window Maximum
HardP1Coding
Given an integer array nums and a window size k, the window slides from the left end to the right end one position at a time. Return an array with the maximum value of each window position (so nums.length - k + 1 values).
Example 1
- Input
- nums = [1,3,-1,-3,5,3,6,7], k = 3
- Output
- [3,3,5,5,6,7]
Example 2
- Input
- nums = [1], k = 1
- Output
- [1]
Example 3
- Input
- nums = [9,11], k = 2
- Output
- [11]
Constraints
- 1 <= nums.length <= 10^5
- -10^4 <= nums[i] <= 10^4
- 1 <= k <= nums.length
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 8. ⌘Enter runs, ⌘⇧Enter submits.