Monotonic stack

A monotonic stack is a stack whose elements are monotonically increasing or decreasing.


Definition of monotonically increasing:

monotonic increasing (not comparable) (mathematics, of a function) always increasing or remaining constant, and never decreasing; contrast this with strictly increasing.


Monotonic Increasing function


Applications of Monotonic stack

  • Finding next greater/smaller element

Example

Next Greater Element