You are given an array of integers&nbsp;nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.

Return the max sliding window.

&nbsp;
Example 1:

Input: nums = [1,3,-1,-3,5,3,6,7], k = 3
Output: [3,3,5,5,6,7]
Explanation: 
Window position                Max
---------------               -----
[1  3  -1] -3  5  3  6  7       3
 1 [3  -1  -3] 5  3  6  7       3
 1  3 [-1  -3  5] 3  6  7       5
 1  3  -1 [-3  5  3] 6  7       5
 1  3  -1  -3 [5  3  6] 7       6
 1  3  -1  -3  5 [3  6  7]      7


Example 2:

Input: nums = [1], k = 1
Output: [1]


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 105
	-104 &lt;= nums[i] &lt;= 104
	1 &lt;= k &lt;= nums.length


class Solution:
    def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
        ans = []
        pq = []

        for i in range(k): heapq.heappush(pq,(-nums[i],i))

        ans.append(-pq[0][0])

        for i in range(k,len(nums)):
            heapq.heappush(pq,(-nums[i],i))
            while pq and pq[0][1] < i-k+1 : heapq.heappop(pq)
            ans.append(-pq[0][0])

        return ans
class Solution {
    public int[] maxSlidingWindow(int[] nums, int k) {
        Deque<Integer> queue = new LinkedList<>();
        int l = 0, r = 0;
        int[] res = new int[nums.length - k + 1];
        int index = 0;
        while (r < nums.length) {
            int n = nums[r++];
            while (!queue.isEmpty() && n > queue.peekLast()) {
                queue.pollLast();
            }
            queue.offer(n);
            while (r - l > k) {
                int m = nums[l++];
                if (m == queue.peekFirst()) {
                    queue.pollFirst();
                }
            }
            if (r - l == k) {
                res[index++] = queue.peekFirst();
            }
        }
        return res;
    }
}
class Solution {
public:
	#define f first
	#define s second
	vector<int> maxSlidingWindow(vector<int>& nums, int k) {
		vector<int> ans;
		priority_queue<pair<int,int>> pq;
		for(int i=0;i<k;i++)pq.push({nums[i],i});

		ans.push_back(pq.top().f);

		for(int i=k; i<nums.size(); i++){
			pq.push({nums[i],i});
			while(!pq.empty() && pq.top().s < i-k+1)pq.pop();
			ans.push_back(pq.top().f);
		}
		return ans;
	}
};
/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number[]}
 */
var maxSlidingWindow = function(nums, k) {
    var i=0, j=0, max=0, deque=[], output=[];
    while(j<nums.length){
        if(deque.length === 0){
            deque.push(nums[j])
        }else if(deque[deque.length-1] > nums[j]){
            deque.push(nums[j])
        }else{
            while(deque[deque.length-1] < nums[j]){
                deque.pop()
            }
            deque.push(nums[j])
        }

        if(j-i+1 === k){
            if(nums[i] === deque[0]){
                output.push(deque.shift());
            }else{
                output.push(deque[0])
            }
            i++;
        }
        j++;

    }
    return output
};
Sliding Window Maximum