Stack Problems for Coding Interviews
A stack fits any problem with nested or most-recent-first structure: matching brackets, evaluating expressions, undo history and parsing. The monotonic stack finds the next greater or smaller element in linear time.
Look for the phrase next greater, previous smaller or nearest valid. Practise explaining what the stack holds at each step and why elements are popped, and bound the total work by showing each item is pushed and popped once.
Coding problems
- Valid Parentheses (Basic)
- Longest Valid Parentheses (Advanced)
- Score of Parentheses (Intermediate)
- Remove Outer Parentheses (Basic)
- Remove Invalid Parentheses (Intermediate)
- Valid Parenthesis With Wildcards (Advanced)
- Generate Balanced Bracket Types (Basic)
- Stack With Middle Operations (Intermediate)
- Glob File Matcher (Intermediate)
- Boolean Parenthesization Count (Basic)
- Expression AST Simplifier (Intermediate)
- Symbolic Differentiation (Intermediate)
- Binary Tree Inorder Traversal (Basic)
- Binary Tree Preorder Traversal (Basic)
- Min Stack Operations (Basic)
- Basic Calculator (Advanced)
- Basic Calculator II (Intermediate)
- Validate Stack Sequences (Intermediate)
- Exclusive Time of Functions (Intermediate)
- Minimum Add to Make Parentheses Valid (Basic)
- Reverse Substrings Between Parentheses (Intermediate)
- Sliding Window Maximum Values (Advanced)
- Fraction to Recurring Decimal (Intermediate)
- Max Stack Operations (Advanced)
- Merge Equal Adjacent Nodes (Intermediate)
- Construct Maximum Binary Tree (Intermediate)
- Construct String From Binary Tree (Basic)
- Maximum Height by Stacking Cuboids (Advanced)
- Number of Atoms (Advanced)
- Basic Calculator III (Advanced)
- Minimum Insertions to Balance Parentheses (Intermediate)
- Parentheses String Can Be Valid (Intermediate)
- Maximum Nesting Depth of Parentheses (Basic)
- Monotonic Array (Basic)
- Implement Queue Using Stacks (Basic)
- Stack With Increment Operation (Intermediate)
- Maximum Frequency Stack (Advanced)
- Dinner Plate Stacks (Advanced)
- Build an Array With Stack Operations (Basic)
- Constrained Subsequence Sum (Advanced)
- Minimum Swaps to Make the String Balanced (Intermediate)
- Count Balanced Bracket Prefixes (Basic)
- Stack Sortable Permutation Check (Intermediate)
- Progressive Tax Total (Intermediate)
- Stacked Discount Final Price (Basic)
- Shipping Cost by Weight Brackets (Basic)
- Stack Machine Final Top (Intermediate)
Related
- Sliding window problems
- Dynamic programming problems
- Graph problems
- Practice coding problems online
- All interview question topics
Frequently asked questions
How do I get good at stack problems?
Solve a few problems of each difficulty, name the pattern after you solve each one, and revisit the ones you needed hints for a week later. The list on this page is ordered so you can start with the basic ones.
Can I run stack problems online here?
Yes. Every problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and six more languages, with no setup.