Sliding Window Maximum (LC #239) finds the max in each window of size . Use a monotonic decreasing deque storing indices. For each element: remove indices outside the window from the front, remove smaller elements from the back (they can't be max while current exists), add current index. The front is always the window max. This runs in time because each element enters and leaves the deque once. Space is . This combines sliding window with monotonic deque patterns.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/meta-interview-prep/stacks-queues/sliding-window-maximum
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████████████████████████████████████████████████████████████████████████████