DDSA Solutions

Monotonic Stack

13 problems · 11 with full explanations

1 Easy4 Medium3 Hard
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.

How to practice

To practice Monotonic Stack problems effectively, start with the Easy problems listed below, trace through each solution on paper, then re-implement without looking. When you can recognise the monotonic stack pattern within 30 seconds of reading a new problem, move on to Medium difficulty. Use the related topic pages and our study guide for a structured progression.

Open the full study guide →

Start here (Easy + explained)

All Monotonic Stack problems