Not a linear solution, instead, it is of O(nlogk) complexity, since add, pop and remove operation of PriorityQueue cost O(logk) time.

What we need to do is just maintain a heap, that heap top gets the maximal value of the k elements.

Since we know which element is removed and which is added to the queue, the solution seems easy to understand.

```
public class Solution {
public int[] maxSlidingWindow(int[] nums, int k) {
int len = nums.length;
int[] result = new int[len - k + 1];
if(nums.length == 0) return new int[0];
Queue<Integer> queue = new PriorityQueue<Integer>(new Comparator<Integer>(){
@Override
public int compare(Integer i1, Integer i2){
return Integer.compare(i2, i1);
}
});
for(int i = 0; i < k; i ++){
queue.add(nums[i]);
}
result[0] = queue.peek();
for(int i = k; i < len; i ++){
queue.remove(nums[i - k]);
queue.add(nums[i]);
result[i - k + 1] = queue.peek();
}
return result;
}
```

Could somebody suggest some linear solutions? The hint of using deque seems not that reasonable. We still need to maintain the k elements in the window in order.

Thank you,