Mental Model
Keep track of useful elements in a window using a double-ended queue to quickly find the maximum.
Analogy: Imagine a line of people waiting to enter a room, but only the tallest people stay in line because shorter ones behind them can't be the tallest in the group.
Array: [2, 1, 3, 4, 6, 3, 8, 9, 10, 12, 56] Window size = 4 Deque stores indices of elements in decreasing order of values Deque: front -> [index of max] -> ... -> back Example: Window: 2 1 3 4 Deque: [0 -> 2 -> 3] (values 2 -> 3 -> 4)
