Least You Need to Know: Monotonic Stacks for Range Boundaries and Histogram Areas
Otevřít lekci
Monotonic stacks do more than next-greater queries: they also expose the nearest smaller or larger boundary on each side. That boundary view powers classic problems like largest rectangle in a histogram and contribution counting.