Data Structures19 sections · 729 units
Open in Course

Vocabulary - Monotonic Stack

Ordered elements

A monotonic stack maintains elements in sorted order. Either:

1.1. Monotonic decreasing: elements decrease from bottom to top

2.2. Monotonic increasing: elements increase from bottom to top

When you push a new element, you first pop all elements that violate the monotonic property. This "cleanup" before pushing is what gives monotonic stacks their power.