What is a Monotonic Stack?

What is a Monotonic Stack?

Approach: Describe a stack that maintains a sorted order of elements.

A stack where elements are either strictly increasing or strictly decreasing. When a new element breaks the order, elements are popped until the order is restored. Useful for 'next greater element' problems.

Follow-up: What is the time complexity of n operations on a monotonic stack?

Key concepts: next greater element, ordering.