Maximum of each sliding window

Slide a window of k numbers one position to the right at a time. Record the largest number in each full window.

The deque holds candidate indices. Their values decrease from front to back.

Remove expired indices from the front. From the back, remove values less than or equal to the new value. The new one stays in the window longer.

Each index enters once and leaves at most once. All maxima take O(n) time. The deque uses O(k) space, with separate storage for the answers.