# CODE

```python
class Solution:
    def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:       
        window = deque()
        result = []
        # Monotonic increasing queue
        for i, num in enumerate(nums):
            # The right element in queue represents the 
            # max we have seen in the window so far
            while window and window[-1][0] < num:
                window.pop()
            window.append((num, i))
            
            # Keep only k elements in window
            while i - window[0][1] + 1 > k:
                window.popleft()
            
            result.append(window[0][0])
        
        # First k - 1 elements in the result are when
        # we didn't have the full window to begin with
        return result[k - 1:]
            
        
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://chiragjain.gitbook.io/neetcode/239-sliding-window-maximum/code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
