Use a deque that maintains indices in decreasing order of their values. The front always holds the maximum.
Remove indices outside the current window from front.
Remove indices from back while their values are smaller than the current element (they can never be maximum).
Add current index to back.
Front of deque is the maximum for current window.