Data Structures19 sections · 729 units
Open in Course

Monotonic Stack Variants

Increasing vs decreasing

You've seen two types of monotonic stacks:

1.1. Monotonic decreasing (biggest on bottom): finds next greater element. Pop when current is larger.

2.2. Monotonic increasing (smallest on bottom): finds next smaller element. Pop when current is smaller. Choose based on what relationship you're looking for. "Next greater" uses decreasing. "Next smaller" uses increasing.