You are given an integer array nums and an integer k. There is a sliding window of size k moving from the left to the right of the array. You can only see the k numbers in the window. Each time the window moves one position to the right, return the maximum number in the window.
Return an array of the maximum values for each window position.
nums: [1, 3, -1, -3, 5, 3, 6, 7]
|------|
|------|
|------|
|------|
|------|
|------|
Input: nums = [1, 3, -1, -3, 5, 3, 6, 7], k = 3 Output: [3, 3, 5, 5, 6, 7] Explanation: Window [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.
Input: nums = [1], k = 1 Output: [1] Explanation: The single window contains only one element.
1 <= nums.length <= 10^5-10^4 <= nums[i] <= 10^41 <= k <= nums.lengthnums = [1, 3, -1, -3, 5, 3, 6, 7], k = 3