Sliding Window Maximum
Return the maximum value in each contiguous window of length k, from left to right.
Example 1
nums = [2,1,5,3,4]
k = 3[5,5,5]Explanation
[2,1,5], [1,5,3] and [5,3,4] each have maximum 5.
Example 2
nums = [-3,-2,-5]
k = 1[-3,-2,-5]Explanation
With k=1 each window contains its original value, including negatives.
Example 3
nums = [7,7]
k = 2[7]Explanation
The only full-length window has maximum 7; duplicates do not add outputs.
Constraints
- 1 <= k <= len(nums) <= 100000
- Values are signed 32-bit integers
Function contract
maxSlidingWindowArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[2,1,5,3,4]3