Skip to main content

Monotonic Stack

Maintain a sorted stack to find next/previous greater or smaller elements in O(n).

6 problems 1 Easy 4 Medium 1 Hard

Problems (6)

Problem Link
Largest Rectangle in Histogram
Next Greater Element I
Sum of Subarray Minimums
Online Stock Span
132 Pattern
Remove Duplicate Letters

Related Guide

Monotonic Stack — Complete Guide With LeetCode Problems [2026] →

Monotonic stacks solve next-greater-element and histogram problems in O(n). The pattern, both varian…

Enjoying this free content?

If this saved you time, buying me a coffee keeps new content coming.

Buy me a coffee
Buy me a coffee