Problem: Return the maximum in each sliding window of size .
Naive: . Optimal: Monotonic deque storing indices in decreasing value order.
For each element: remove out-of-window indices from front, remove smaller elements from back (they can never be max), add current index. Front always holds max.
Time: . Space: .
See the implementation unit for code.