For sliding window maximum:
Store indices (not values) in the deque, so you can check if elements are in the current window.
Maintain decreasing order: nums[deque.front()] >= nums[deque.back()].
When adding index , remove indices from the back while nums[i] >= nums[deque.back()]. Smaller elements can't be the maximum while is in the window.
Remove indices from the front that are outside the window (index ).
The front is always the maximum of the current window.