Use a monotonic decreasing deque. The front always holds the index of the maximum element in the current window.
When adding a new element, remove all smaller elements from the back. They can never be the maximum while this larger element exists in the window. Also remove elements from the front that are outside the window.
Why monotonic decreasing? If nums[i] > nums[j] and i > j, then nums[j] can never be the window maximum as long as nums[i] is in the window. So we discard it.
With nums = [1, 3, -1, -3, 5] and k = 3: after processing 1, deque is [0]. After 3, pop 1 (smaller), deque is [1]. After -1, deque is [1, 2]. Window [1,3,-1] has max at index 1, which is 3.