A maximum cannot be undone
transcript
You want the peak of each window of k values. A running total drops one value by subtraction. Can a maximum do the same?
Track only the entering maximum, and the five stays. Even after it has left. The peaks come out as five, five, five. A deque lets the five expire. It goes as soon as it leaves.
The first window is five and one. The peak is five. The next window is one and one. The five has left the window. The peak is one. The last window is the same, so its peak is one too.
It keeps candidate positions, not plain values. A new value pops weaker ones off the back. The front expires at position i minus k. The next candidate takes over.
A maximum needs a deque of candidates. Pop weaker values off the back. Expire the front at i minus k. Full breakdown in the lecture.