You want to master monotonic stacks and queues, but where do you start? Which problems should you solve first? How do you progress from beginner to interview-ready?
This roadmap answers all those questions. It's a structured 6-week learning path that takes you from zero to mastery, with curated problems, clear milestones, and a proven progression.
Follow this roadmap, and in 6 weeks, you'll confidently solve any monotonic stack/queue problem in interviews.
How to Use This Roadmap
Time Commitment
- Beginner: 1-2 hours per day, 5 days per week
- Intermediate: 2-3 hours per day, 5 days per week
- Total: 6 weeks to interview-ready
Progression Philosophy
- Master fundamentals before moving to advanced
- Solve problems in order (builds on previous knowledge)
- Understand why monotonic order works, not just memorize
- Trace stack state on every problem
- Review mistakes and understand amortized analysis
Milestones
- ✅ Week 2: Solve basic next greater element problems confidently
- ✅ Week 3: Master histogram and contribution technique
- ✅ Week 4: Handle duplicates and edge cases correctly
- ✅ Week 6: Interview-ready for any monotonic stack/queue problem
Phase 1: Foundations (Weeks 1-2)
Goal: Understand monotonic decreasing stack and solve next greater element problems.
Week 1: Monotonic Decreasing Stack
Concepts to Learn:
- What is a monotonic stack?
- Why decreasing order finds next greater element
- Stack vs array for this pattern
- Amortized O(n) analysis
Required Reading:
- Complete Monotonic Stack & Queue Guide - Read sections 1-4
- Monotonic Decreasing Stack Template
- Why Stack Beats Brute Force
- Pattern Recognition in 30 Seconds
Problems to Solve (5 problems):
| # | Problem | Difficulty | Key Learning |
|---|---|---|---|
| 1 | Next Greater Element I (#496) | Easy ⭐ | Basic template |
| 2 | Next Greater Element II (#503) | Medium ⭐⭐ | Circular arrays |
| 3 | Daily Temperatures (#739) | Medium ⭐⭐ | Distance calculation |
| 4 | Final Prices With Discount (#1475) | Easy | Next smaller variant |
| 5 | Buildings With Ocean View (#1762) | Medium | Visibility pattern |
Practice Template:
# Memorize this template
stack = [] # Store indices
result = [-1] * n
for i in range(n):
# Pop smaller elements (found their next greater)
while stack and nums[i] > nums[stack[-1]]:
idx = stack.pop()
result[idx] = nums[i]
stack.append(i)Checkpoint: Can you solve Daily Temperatures without looking at solutions? Can you explain why it's O(n)?
Week 2: Monotonic Increasing Stack
Concepts to Learn:
- Why increasing order finds next smaller element
- Histogram problems and area calculation
- Sentinels for edge case handling
- Width calculation (excluding boundaries)
Required Reading:
Problems to Solve (6 problems):
| # | Problem | Difficulty | Key Learning |
|---|---|---|---|
| 6 | Largest Rectangle in Histogram (#84) | Hard ⭐⭐⭐ | Canonical problem |
| 7 | Maximal Rectangle (#85) | Hard ⭐⭐⭐ | 2D extension |
| 8 | Remove K Digits (#402) | Medium | Greedy + stack |
| 9 | Remove Duplicate Letters (#316) | Medium | Lexicographic order |
| 10 | Create Maximum Number (#321) | Hard | Complex variant |
| 11 | Shortest Unsorted Subarray (#581) | Medium | Finding boundaries |
Practice Template:
# Histogram template with sentinels
heights = [0] + heights + [0]
stack = []
max_area = 0
for i in range(len(heights)):
while stack and heights[i] < heights[stack[-1]]:
h_idx = stack.pop()
height = heights[h_idx]
width = i - stack[-1] - 1 # Exclude boundaries
area = height * width
max_area = max(max_area, area)
stack.append(i)Checkpoint: Can you solve Largest Rectangle in Histogram and explain the width calculation? Can you handle edge cases without special logic?
Phase 2: Advanced Patterns (Weeks 3-4)
Goal: Master monotonic queue, contribution technique, and handle duplicates.
Week 3: Monotonic Queue and Contribution Technique
Concepts to Learn:
- Deque vs stack (why need both ends)
- Sliding window maximum O(n) solution
- Contribution technique for counting problems
- Asymmetric comparison for duplicates
Required Reading:
Problems to Solve (7 problems):
| # | Problem | Difficulty | Key Learning |
|---|---|---|---|
| 12 | Sliding Window Maximum (#239) | Hard ⭐⭐⭐ | Canonical queue problem |
| 13 | Constrained Subsequence Sum (#1425) | Hard | DP + monotonic queue |
| 14 | Jump Game VI (#1696) | Medium | DP optimization |
| 15 | Sum of Subarray Minimums (#907) | Medium ⭐⭐ | Contribution technique |
| 16 | Sum of Subarray Ranges (#2104) | Medium | Apply twice (max & min) |
| 17 | Shortest Subarray with Sum ≥ K (#862) | Hard | Deque + prefix sum |
| 18 | Longest Continuous Subarray (#1438) | Medium | Two deques |
Practice Templates:
# Monotonic Queue Template
from collections import deque
dq = deque()
for i in range(n):
# Remove out-of-window
while dq and dq[0] < i - k + 1:
dq.popleft()
# Maintain decreasing order
while dq and nums[i] > nums[dq[-1]]:
dq.pop()
dq.append(i)
if i >= k - 1:
result.append(nums[dq[0]])
# Contribution Technique Template
# Right: strict <
while stack and arr[i] < arr[stack[-1]]:
right[stack.pop()] = i
# Left: non-strict <= (handles duplicates)
while stack and arr[i] <= arr[stack[-1]]:
left[stack.pop()] = i
# Count = (i - left[i]) * (right[i] - i)Checkpoint: Can you solve Sliding Window Maximum in O(n)? Can you explain asymmetric comparison for duplicates?
Week 4: Range Queries and Stock Span
Concepts to Learn:
- Stock span pattern (accumulating spans)
- Trapping rain water (two approaches)
- Range queries optimization
- When to store indices vs values
Required Reading:
Problems to Solve (6 problems):
| # | Problem | Difficulty | Key Learning |
|---|---|---|---|
| 19 | Online Stock Span (#901) | Medium ⭐⭐ | Accumulating spans |
| 20 | Trapping Rain Water (#42) | Hard ⭐⭐⭐ | Stack or two pointers |
| 21 | Maximum Width Ramp (#962) | Medium | Width optimization |
| 22 | Car Fleet (#853) | Medium | Implicit monotonic stack |
| 23 | Number of Visible People (#1944) | Hard | Visibility counting |
| 24 | 132 Pattern (#456) | Medium | Complex pattern matching |
Practice Template:
# Stock Span Template
class StockSpanner:
def __init__(self):
self.stack = [] # (price, span)
def next(self, price):
span = 1
while self.stack and self.stack[-1][0] <= price:
span += self.stack.pop()[1] # Accumulate spans
self.stack.append((price, span))
return spanCheckpoint: Can you solve Stock Span and explain span accumulation? Can you implement Trapping Rain Water with both approaches?
Phase 3: Mastery (Weeks 5-6)
Goal: Handle all edge cases, debug efficiently, and recognize patterns instantly.
Week 5: Edge Cases and Debugging
Concepts to Learn:
- Common mistakes in next greater problems
- Histogram edge cases (sentinels, width calculation)
- Sliding window max mistakes (boundary, timing)
- Circular array handling
- Systematic debugging process
Required Reading:
Problems to Solve (6 problems):
| # | Problem | Difficulty | Key Learning |
|---|---|---|---|
| 25 | Maximum Binary Tree (#654) | Medium | Tree construction |
| 26 | Sum of Subarray Minimums (#907) | Medium | Review with duplicates |
| 27 | Next Greater Node in Linked List (#1019) | Medium | Linked list variant |
| 28 | Minimum Cost Tree From Leaf Values (#1130) | Medium | DP + stack |
| 29 | Minimum Number of Removals (#1673) | Hard | Bidirectional stack |
| 30 | Largest Rectangle in Histogram (#84) | Hard | Review and optimize |
Debugging Checklist:
When your solution fails:
1. ✓ Verify monotonicity direction (increasing vs decreasing)
2. ✓ Check comparison operator (<, >, <=, >=)
3. ✓ Trace stack state at each iteration
4. ✓ Verify result initialization (pre-allocated?)
5. ✓ Test edge cases (empty, single, duplicates)
6. ✓ Check boundary calculations (off-by-one?)Checkpoint: Can you debug a failing solution in under 5 minutes? Can you identify the mistake pattern immediately?
Week 6: Pattern Recognition and Interview Prep
Concepts to Learn:
- Instant pattern recognition (30 seconds)
- Monotonic stack vs other patterns
- When NOT to use monotonic stack
- Interview communication strategies
Required Reading:
- Monotonic Stack vs Other Patterns
- Pattern Recognition in 30 Seconds - Review
- Complete Guide - Review all sections
Problems to Solve (8 problems - Mixed Review):
| # | Problem | Difficulty | Key Learning |
|---|---|---|---|
| 31 | Daily Temperatures (#739) | Medium | Speed drill (5 min) |
| 32 | Largest Rectangle (#84) | Hard | Speed drill (10 min) |
| 33 | Sliding Window Maximum (#239) | Hard | Speed drill (10 min) |
| 34 | Sum of Subarray Minimums (#907) | Medium | Speed drill (8 min) |
| 35 | Next Greater Element II (#503) | Medium | Speed drill (6 min) |
| 36 | Trapping Rain Water (#42) | Hard | Speed drill (12 min) |
| 37 | Stock Span (#901) | Medium | Speed drill (7 min) |
| 38 | Maximal Rectangle (#85) | Hard | Speed drill (15 min) |
Pattern Recognition Drill:
For each problem, identify in 30 seconds:
- Is it monotonic stack/queue?
- Which variant (decreasing, increasing, queue)?
- What's the key insight?
- What are the edge cases?
Interview Simulation:
- Solve 2 random problems from above list in 45 minutes
- Explain your approach before coding
- Handle follow-up questions
- Optimize space/time if asked
Checkpoint: Can you recognize the pattern in 30 seconds? Can you solve any problem from the list without hints?
Problem Summary by Pattern
Monotonic Decreasing Stack (Next Greater)
- Next Greater Element I, II (#496, #503)
- Daily Temperatures (#739)
- Buildings With Ocean View (#1762)
- Final Prices With Discount (#1475)
- Next Greater Node in Linked List (#1019)
Monotonic Increasing Stack (Next Smaller / Histogram)
- Largest Rectangle in Histogram (#84)
- Maximal Rectangle (#85)
- Trapping Rain Water (#42)
- Remove K Digits (#402)
- Remove Duplicate Letters (#316)
- Maximum Binary Tree (#654)
Monotonic Queue (Sliding Window Max/Min)
- Sliding Window Maximum (#239)
- Constrained Subsequence Sum (#1425)
- Jump Game VI (#1696)
- Shortest Subarray with Sum ≥ K (#862)
- Longest Continuous Subarray (#1438)
Contribution Technique
- Sum of Subarray Minimums (#907)
- Sum of Subarray Ranges (#2104)
- Number of Visible People (#1944)
Range Queries / Stock Span
- Online Stock Span (#901)
- Maximum Width Ramp (#962)
- Car Fleet (#853)
- 132 Pattern (#456)
Weekly Progress Tracker
Week 1 Checklist
-
Read decreasing stack template
-
Solve 5 next greater problems
-
Understand amortized O(n) analysis
-
Can explain why decreasing order works
Week 2 Checklist
-
Read increasing stack template
-
Solve Largest Rectangle in Histogram
-
Master sentinel technique
-
Understand width calculation
Week 3 Checklist
-
Read monotonic queue template
-
Solve Sliding Window Maximum
-
Master contribution technique
-
Handle duplicates correctly
Week 4 Checklist
-
Solve Stock Span problem
-
Master Trapping Rain Water (both approaches)
-
Understand range query optimization
-
Know when to store indices vs values
Week 5 Checklist
-
Review all common mistakes
-
Debug failing solutions systematically
-
Handle all edge cases
-
Master circular array technique
Week 6 Checklist
-
Recognize patterns in 30 seconds
-
Solve problems under time pressure
-
Explain solutions clearly
-
Interview-ready confidence
Study Tips
Daily Routine
Day 1-3 (New Concepts):
- Read required articles (30-45 min)
- Solve 1-2 problems (60-90 min)
- Review and trace solutions (15-30 min)
Day 4-5 (Practice):
- Solve 2-3 problems (90-120 min)
- Debug and optimize (30 min)
- Review mistakes (15 min)
Common Pitfalls to Avoid
❌ Memorizing without understanding
- ✅ Trace stack state by hand
- ✅ Understand why monotonic order works
❌ Skipping edge cases
- ✅ Test empty, single, duplicates, increasing, decreasing
❌ Not practicing debugging
- ✅ Intentionally break code and fix it
- ✅ Use systematic debugging checklist
❌ Rushing through problems
- ✅ Solve fewer problems deeply
- ✅ Understand every line of code
Bug Journal Template
For each mistake, record:
Problem: [Name]
Mistake: [What went wrong]
Root Cause: [Why it happened]
Fix: [How to prevent]
Pattern: [Common mistake category]Interview Readiness Checklist
After 6 weeks, you should be able to:
Pattern Recognition
-
Identify monotonic stack problems in 30 seconds
-
Distinguish from sliding window, two pointers, DP
-
Know which variant to use (decreasing, increasing, queue)
Implementation
-
Write decreasing stack template from memory
-
Write increasing stack template from memory
-
Write monotonic queue template from memory
-
Handle duplicates with asymmetric comparison
Problem Solving
-
Solve Daily Temperatures in under 5 minutes
-
Solve Largest Rectangle in Histogram in under 10 minutes
-
Solve Sliding Window Maximum in under 10 minutes
-
Solve Sum of Subarray Minimums in under 8 minutes
Debugging
-
Debug failing solutions in under 5 minutes
-
Identify common mistake patterns instantly
-
Handle all edge cases without hints
Communication
-
Explain amortized O(n) analysis clearly
-
Justify why monotonic stack is optimal
-
Walk through solution step-by-step
-
Handle follow-up questions confidently
Next Steps After Completion
You're interview-ready! But to maintain mastery:
- Weekly Practice: Solve 2-3 monotonic stack problems per week
- Mock Interviews: Practice explaining solutions out loud
- Teach Others: Solidify understanding by teaching
- Explore Variants: Try harder problems (#2281, #2334, #2398)
Resources
Core Articles:
- Complete Monotonic Stack & Queue Guide
- Decreasing Stack Template
- Increasing Stack Template
- Monotonic Queue Template
Troubleshooting:
Advanced Topics:
Conclusion
This roadmap takes you from zero to interview-ready in 6 weeks. The key is consistent practice and deep understanding.
Remember:
- Master fundamentals before advanced topics
- Understand why, not just memorize
- Practice debugging systematically
- Review mistakes and learn from them
Follow this roadmap, and you'll confidently solve any monotonic stack/queue problem in your next interview.
Good luck! 🚀
Want to Practice LeetCode Smarter?
LeetCopilot is a free browser extension that enhances your LeetCode practice with AI-powered hints, personalized study notes, and realistic mock interviews — all designed to accelerate your coding interview preparation.
Also compatible with Edge, Brave, and Opera
