Mental Model
Keep track of the largest values in the current window using a special list that quickly removes smaller values.
Analogy: Imagine a line of people waiting to enter a ride, but only the tallest people stay in line because shorter ones get blocked and leave. The tallest person at the front is always the leader of 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 Example: Deque: [6, 7, 8, 9] (indices of values 8, 9, 10, 12) Window covers elements: 8, 9, 10, 12 Max is at front: 12