Monotonic stack and deque
- Stage
- 6
- Module
- M6.11
- Lessons
- 1
In this module
- Use a monotonic stack to find the next greater element in linear time.
- Track the maximum in a sliding window with a monotonic deque.
- Reuse the same sliding-window deque to answer a feasibility check over a shrinking range.
- Solve classic window-maximum problems in linear time.
Before this module
Lessons
Practice
Try these on the judges. Each link opens the problem on WMOJ or DMOJ.
- 2019 S4Tourism (opens on DMOJ in a new tab) DMOJ
Plan a multi-day itinerary that visits the most cities under a travel budget.
Why DMOJ: An older windowed-search problem that still makes good practice for this module.
- 2026 S4Minecarts (opens on WMOJ in a new tab) WMOJ
Track which minecarts can still reach the end of the line as tracks change.