Monotonic Stack Concept & Pattern
Original12/22/25Less than 1 minute
🧠 Concept
Leverage stack to maintain a monotonically increasing or decreasing list:
- Every element in the array should be pushed into the stack.
- Pop smaller values, then push new big value (decreasing stack)
- Pop bigger values, then push new small value (increasing stack)
Problem types
- Next greater/smaller value or Previous greater/smaller value problem.
- Remove elements while keeping order and optimizing result.
🛠️ Pattern
- Store indices in stack for convenience
