DSA Master › Topic 8

Stack & Monotonic Stack

A stack handles anything nested or last-in-first-out, like brackets or expressions. A monotonic stack keeps its elements in sorted order. When a new element breaks that order, you pop, and each pop answers a "next greater" or "previous smaller" question in O(n) total.

Concepts

How to recognise it

Common pitfalls

Problems

  1. Valid Parentheses (Easy)
  2. Min Stack (Medium)
  3. Evaluate Reverse Polish Notation (Medium)
  4. Daily Temperatures (Medium)
  5. Next Greater Element I (Easy)
  6. Largest Rectangle in Histogram (Hard)
  7. Online Stock Span (Medium)
  8. Remove K Digits (Medium)
  9. Asteroid Collision (Medium)