Dashboard
LC #239
Sliding Window Maximum
Pattern · ?AmazonGoogleMetaMicrosoftBloomberg
Problem
Return the maximum value in each sliding window of size k as it moves across the array.
Constraints
- 1 ≤ nums.length ≤ 10⁵
- -10⁴ ≤ nums[i] ≤ 10⁴
- 1 ≤ k ≤ nums.length
Example
- Input
- nums = [1,3,-1,-3,5,3,6,7], k = 3
- Output
- [3,3,5,5,6,7]
- Why
- Max of each window: [1,3,-1]=3, [3,-1,-3]=3, [-1,-3,5]=5, [-3,5,3]=5, [5,3,6]=6, [3,6,7]=7
Spot the pattern
Which pattern cracks it?
Hints
One at a time