Loading...
Given an integer array nums and a window size k, slide a window of exactly k consecutive elements across nums from left to right, one position at a time.
Return an array containing the maximum of each window, in order. The result has nums.length - k + 1 entries.
Input: nums = [1,3,-1,-3,5,3,6,7], k = 3
Output: [3,3,5,5,6,7]
Explanation:
Window [1 3 -1] -3 5 3 6 7 → max 3
Window 1 [3 -1 -3] 5 3 6 7 → max 3
Window 1 3 [-1 -3 5] 3 6 7 → max 5
Window 1 3 -1 [-3 5 3] 6 7 → max 5
Window 1 3 -1 -3 [5 3 6] 7 → max 6
Window 1 3 -1 -3 5 [3 6 7] → max 7
Input: nums = [1], k = 1
Output: [1]
nums.length ≤105nums[i] ≤104nums.lengthClick "Run" to test with sample cases or "Submit" to run all tests.