190. Sliding Window Maximum
HardSliding Window
Given an integer array `nums` and an integer `k`, there is a sliding window of size `k` that moves from the very left of the array to the very right, one position at a time. Return an array of the maximum value in each window position. For example, given nums = [1,3,-1,-3,5,3,6,7] and k = 3, the windows are: - [1,3,-1] max = 3 - [3,-1,-3] max = 3 - [-1,-3,5] max = 5 - [-3,5,3] max = 5 - [5,3,6] max = 6 - [3,6,7] max = 7 So the answer is [3,3,5,5,6,7].
Examples
Input: [1,3,-1,-3,5,3,6,7] 3
Output: [3,3,5,5,6,7]
Explanation: The sliding window of size 3 moves through the array and the maximum of each window is [3,3,5,5,6,7].
Constraints
- 1 <= nums.length <= 10^5
- -10^4 <= nums[i] <= 10^4
- 1 <= k <= nums.length
Loading...
Run checks all cases above. Submit evaluates all test cases.