Sliding Window — Monotonic Deque LeetCode 239
Sliding Window Maximum / visualized
The max of every length-k window, in O(n). A monotonic deque holds candidate
indices with values in decreasing order — so the front is always the current window's max.
Each element is pushed and popped at most once, which is what beats the naïve O(n·k).
Execution
idle
← front (max)back →
stores indices; values shown for clarity · always decreasing front → back
Press Run to begin.
Java · running line
in window
in deque
front = max
evicted / popped