The Core Rule
Before enqueuing a new element at the rear, you must `pop_back` all elements that violate the desired monotonic order (e.g., all elements smaller than the new element). Only then do you `push_back` the new element.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
A specialized Double-Ended Queue (Deque) whose elements are strictly strictly increasing or decreasing. Used heavily in Sliding Window optimization problems.
Before enqueuing a new element at the rear, you must `pop_back` all elements that violate the desired monotonic order (e.g., all elements smaller than the new element). Only then do you `push_back` the new element.
Like a standard queue, elements fall out of scope from the front. If the front element's index is no longer within the sliding window, you `pop_front`.