Skip to content
CCC Python Course

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

  1. 1Monotonic stack and deque

Practice

Try these on the judges. Each link opens the problem on WMOJ or DMOJ.

  1. 2019 S4
    Tourism (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.

  2. 2026 S4
    Minecarts (opens on WMOJ in a new tab) WMOJ

    Track which minecarts can still reach the end of the line as tracks change.