Glossary term

What is monotonic stack? Meaning for developers

A stack kept in sorted order (always going up or always going down) by popping items that no longer matter. It solves next greater element and similar questions in O(n).

Learn it properly · DSALesson 40: Monotonic StackFind the next bigger item. It also solves temperatures, stock spans, histograms and rain water.

All DSA terms

Related terms

← All glossary terms, A to Z