DDSA Solutions

Monotonic Queue

2 problems · 2 with full explanations

0 Easy2 Medium0 Hard
A monotonic queue (deque) answers sliding window min/max in O(1) amortized. Maintain indices in decreasing (for max) or increasing (for min) order. Remove from the front when indices fall outside the window, and from the back when the new element is more extreme.

How to practice

To practice Monotonic Queue problems effectively, start with the Easy problems listed below, trace through each solution on paper, then re-implement without looking. When you can recognise the monotonic queue pattern within 30 seconds of reading a new problem, move on to Medium difficulty. Use the related topic pages and our study guide for a structured progression.

Open the full study guide →

All Monotonic Queue problems