Skip to content

Data Structures -> Monotonic Stack / Queue

One linear scan, one domination rule: use monotonic stacks for boundaries and deques for fixed-width extrema.

  • Topic slug: data-structures/monotonic-stack-queue
  • Tutorial page: Open tutorial
  • Ladder page: Open ladder
  • Repo problems currently tagged here: 1
  • Repo companion pages: 3
  • Curated external problems: 3

Microtopics

  • previous-smaller
  • next-smaller
  • monotonic-stack
  • monotonic-deque
  • sliding-window-minmax
  • histogram-boundaries

Learning Sources

Source Type
cp-algorithms minimum stack / minimum queue Reference
Competitive Programmer's Handbook Reference

Practice Sources

Source Type
CSES Nearest Smaller Values Practice
CSES Sliding Window Minimum Practice
CSES Advertisement Practice

Repo Companion Material

Material Type
Monotonic Stack / Queue hot sheet quick reference
Nearest Smaller Values note anchor note
Data structures cheatsheet broader chooser

Curated External Problems

Core

Problem Source Difficulty Context Style Prerequisites Tags Why it fits
Nearest Smaller Values CSES Medium Monotonic Stack Implementation; Amortized Stacks; Indices; Strict Comparators Previous-Smaller; Boundary The canonical first boundary-scan problem for the monotonic-stack side of the family.
Sliding Window Minimum CSES Medium Monotonic Deque Implementation; Streaming Deque; Window Expiry; Amortized Reasoning Window-Minimum; Stream The queue-side canonical benchmark where domination pops and window expiry are both visible.

Classics

Problem Source Difficulty Context Style Prerequisites Tags Why it fits
Advertisement CSES Medium Monotonic Stack Implementation; Geometry-On-Array Boundary Indices Histogram; Nearest-Smaller; Rectangle Area A strong follow-up where nearest-smaller boundaries turn directly into widths.

Repo Problems

Code Title Fit Difficulty Pattern Note Solution
NEARESTSMALLERVALUES Nearest Smaller Values primary medium - Note Code

Regeneration

python3 scripts/generate_problem_catalog.py