0% found this document useful (0 votes)
2 views5 pages

Stack Queue

This chapter focuses on mastering stack and queue patterns through 40 problems, categorized into various levels of difficulty. Key topics include monotonic stacks, expression evaluation, and parentheses problems, with a list of must-master problems for interviews. The chapter emphasizes understanding core patterns and concepts related to stack and queue implementations, as well as providing interview advice for common problem types.

Uploaded by

psy02873
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Stack Queue

This chapter focuses on mastering stack and queue patterns through 40 problems, categorized into various levels of difficulty. Key topics include monotonic stacks, expression evaluation, and parentheses problems, with a list of must-master problems for interviews. The chapter emphasizes understanding core patterns and concepts related to stack and queue implementations, as well as providing interview advice for common problem types.

Uploaded by

psy02873
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Stacks and Queues quietly appear inside array, string, graph, tree, and even DP problems.

By the end of this chapter, you'll stop seeing "stack questions" and start recognizing
monotonic stack, expression parsing, deque, and BFS queue patterns.

📖 CHAPTER 4 — Stack & Queue (40 Problems)


Goal
Master these patterns:
●​ Stack Basics
●​ Queue Basics
●​ Monotonic Stack
●​ Monotonic Queue (Deque)
●​ Expression Evaluation
●​ Parentheses Problems
●​ Next Greater/Smaller Element
●​ Simulation
●​ Design Problems
●​ BFS Queue Applications

Level 1 — Stack Basics (8)


# LC Problem Difficulty Pattern

1 20 Valid Parentheses Easy Stack

2 225 Implement Stack using Queues Easy Design

3 232 Implement Queue using Stacks Easy Design

4 682 Baseball Game Easy Stack Simulation

5 844 Backspace String Compare Easy Stack

6 1047 Remove All Adjacent Duplicates In String Easy Stack

7 1544 Make The String Great Easy Stack

8 1475 Final Prices With a Special Discount Easy Stack


Level 2 — Monotonic Stack (10)
These are among the highest ROI interview problems.

# LC Problem Difficulty Pattern

9 496 Next Greater Element I Easy Monotonic Stack

10 503 Next Greater Element II Medium Circular Monotonic Stack

11 739 Daily Temperatures Medium Monotonic Stack

12 901 Online Stock Span Medium Monotonic Stack

13 84 Largest Rectangle in Histogram Hard Monotonic Stack

14 85 Maximal Rectangle Hard Histogram

15 42 Trapping Rain Water Hard Stack

16 1019 Next Greater Node In Linked List Medium Monotonic Stack

17 1944 Number of Visible People in a Queue Hard Monotonic Stack

18 2289 Steps to Make Array Non-decreasing Hard Monotonic Stack

Level 3 — Parentheses Problems (6)


# LC Problem Difficulty Pattern

19 32 Longest Valid Parentheses Hard Stack

20 921 Minimum Add to Make Parentheses Valid Medium Stack

21 1249 Minimum Remove to Make Valid Parentheses Medium Stack

22 1541 Minimum Insertions to Balance Parentheses Medium Greedy + Stack

23 1190 Reverse Substrings Between Parentheses Medium Stack

24 856 Score of Parentheses Medium Stack


Level 4 — Expression Evaluation (5)
# LC Problem Difficulty Pattern

25 150 Evaluate Reverse Polish Notation Medium Stack

26 224 Basic Calculator Hard Stack

27 227 Basic Calculator II Medium Stack

28 772 Basic Calculator III (Premium) Hard Parsing

29 394 Decode String Medium Stack

Level 5 — Queue & Deque (5)


# LC Problem Difficulty Pattern

30 933 Number of Recent Calls Easy Queue

31 622 Design Circular Queue Medium Queue

32 641 Design Circular Deque Medium Deque

33 239 Sliding Window Maximum Hard Monotonic Queue

34 862 Shortest Subarray with Sum at Least K Hard Deque + Prefix Sum

Level 6 — Advanced Stack/Queue (6)


# LC Problem Difficulty Pattern

35 155 Min Stack Medium Stack Design

36 895 Maximum Frequency Stack Hard Stack + HashMap

37 1673 Find the Most Competitive Subsequence Medium Monotonic Stack

38 735 Asteroid Collision Medium Stack Simulation

39 946 Validate Stack Sequences Medium Stack

40 1209 Remove All Adjacent Duplicates in String II Medium Stack


⭐ Must Master (Top 15)
These show up repeatedly in product-company interviews:
1.​ Valid Parentheses
2.​ Implement Queue using Stacks
3.​ Implement Stack using Queues
4.​ Next Greater Element I
5.​ Daily Temperatures
6.​ Online Stock Span
7.​ Largest Rectangle in Histogram
8.​ Maximal Rectangle
9.​ Longest Valid Parentheses
10.​Evaluate Reverse Polish Notation
11.​Basic Calculator II
12.​Decode String
13.​Sliding Window Maximum
14.​Min Stack
15.​Asteroid Collision

Core Patterns You Must Master


Pattern 1 — Monotonic Increasing Stack
●​ Next Greater Element
●​ Daily Temperatures
●​ Largest Rectangle
●​ Stock Span

Pattern 2 — Monotonic Decreasing Stack


●​ Previous Greater Element
●​ Competitive Subsequence
●​ Visible People

Pattern 3 — Parentheses Matching


●​ Valid Parentheses
●​ Longest Valid Parentheses
●​ Score of Parentheses
●​ Minimum Remove
Pattern 4 — Expression Parsing
●​ Reverse Polish Notation
●​ Basic Calculator I
●​ Basic Calculator II
●​ Decode String

Pattern 5 — Monotonic Queue (Deque)


●​ Sliding Window Maximum
●​ Shortest Subarray with Sum at Least K

Pattern 6 — Design
●​ Min Stack
●​ Circular Queue
●​ Circular Deque
●​ Frequency Stack

📚 Concepts to Learn Alongside


As you solve these problems, understand:
●​ Array-based vs Linked List-based stack/queue implementations
●​ Amortized analysis for stack operations
●​ Monotonic stack invariants
●​ Monotonic queue (deque) invariants
●​ Infix, postfix, and prefix expressions
●​ Shunting Yard algorithm (conceptually)
●​ Queue-based BFS (preparation for Graphs and Trees)

🎯 Interview Advice
If you can solve Daily Temperatures, Largest Rectangle in Histogram, and Sliding
Window Maximum confidently, you'll have mastered three of the most reusable patterns in
interview problem solving. They reappear in many disguised forms across arrays, graphs,
and dynamic programming.

🏆 Chapter Difficulty
⭐⭐⭐☆☆ (Intermediate)

You might also like