DDSA Solutions

Monotonic Stack

13 problems

A monotonic stack maintains elements in strictly increasing or decreasing order. When a new element violates this order, elements are popped and processed. Use for "next greater / smaller element", histogram area, and stock span problems. Each element is pushed and popped at most once — O(n) overall.