monotonicqueue
A monotonic queue is a data structure that maintains its elements in either non-decreasing or non-increasing order. When new elements are added, the queue is modified to preserve this monotonic property. Typically, this involves removing elements from the back of the queue that violate the desired order before adding the new element. For example, in a non-decreasing monotonic queue, if a new element is smaller than the last element in the queue, the last element is removed. This process continues until the new element can be added while maintaining the non-decreasing order.
Monotonic queues are often implemented using a double-ended queue (deque), which allows efficient insertion and deletion