Stacks & Queues

Monotonic stack and deque — the two specialized container patterns that unlock 'next greater' and 'window max' problems.

1 min readInterview · DSA Patterns

A monotonic stack maintains its elements in strict order. By popping violators on every push, it lets us answer "what's the next greater / smaller element?" in amortized O(n). The deque variant adds left-side eviction for sliding-window aggregates.

Finished reading?

Mark it done to track your progress in Interview.

On this page

No Headings