Two deques give the slowest and the fastest
transcript
A dashboard needs two numbers. The slowest reading in the window. And the fastest reading. Do not rescan the window.
One deque keeps positions. Its values fall from front to back. The front is the maximum. A new value pushes weaker ones off the back.
A second deque rises. Its front is the minimum. A new value pushes larger ones off the back.
Every reading goes into both deques. Old positions expire from the front. Subtract the two fronts for the spread.
Six values, window of three. Twenty deque steps in all. Steps grow with values, not width.
Readings arrive: five, three, four. Five joins. Three joins behind it. Four arrives. It removes three from the back. The front is still five. That is the maximum. A window of three is full.
Two deques give both extremes. Each position joins once and leaves once, so the pass is linear. Full breakdown in the lecture.