For each index :
Remove indices from front that are outside window ().
Remove indices from back while . These can never be the answer.
Push to back.
If (window is full), the front is the maximum. Each index is pushed once and popped at most once. Total: . Time: . Space: .