YUNOVA · Data Structures & Algorithms · Module 13: Advanced data structures
Monotonic stack and deque problems
Monotonic stack and deque problems
Key points
- A monotonic stack keeps elements in increasing or decreasing order.
- It finds the next greater or smaller element for every item in O(n).
- A monotonic deque gives the sliding window maximum in O(n).