Stack
46 problems · 20 with full explanations
10 Easy17 Medium5 Hard
Stacks support LIFO (last-in, first-out) operations in O(1). Key patterns: balanced parentheses, next greater element (monotonic stack), function call simulation, and undo/redo. A monotonic stack maintains a strictly increasing or decreasing order to answer range queries efficiently.
How to practice
To practice Stack 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 stack 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.
Start here (Easy + explained)
All Stack problems
- 20.Valid ParenthesesEasy
- 32.Longest Valid ParenthesesHard
- 85.Maximal RectangleHard
- 114.Flatten Binary Tree to Linked ListMedium
- 144.Binary Tree Preorder TraversalEasy
- 145.Binary Tree Postorder TraversalEasy
- 316.Remove Duplicate LettersMedium
- 321.Create Maximum NumberUnknown
- 331.Verify Preorder Serialization of a Binary TreeUnknown
- 386.Lexicographical NumbersMedium
- 590.N-ary Tree Postorder TraversalEasy
- 678.Valid Parenthesis StringMedium
- 726.Number of AtomsHard
- 769.Max Chunks To Make SortedMedium
- 856.Score of ParenthesesMedium
- 880.Decoded String at IndexMedium
- 921.Minimum Add to Make Parentheses ValidMedium
- 962.Maximum Width RampMedium
- 1021.Remove Outermost ParenthesesEasy
- 1081.Smallest Subsequence of Distinct CharactersMedium
- 1096.Brace Expansion IIHard
- 1106.Parsing A Boolean ExpressionHard
- 1111.Maximum Nesting Depth of Two Valid Parentheses StringsMedium
- 1190.Reverse Substrings Between Each Pair of ParenthesesMedium
- 1381.Design a Stack With Increment OperationUnknown
- 1475.Final Prices With a Special Discount in a ShopEasy
- 1526.Minimum Number of Increments on Subarrays to Form a Target ArrayUnknown
- 1541.Minimum Insertions to Balance a Parentheses StringMedium
- 1574.Shortest Subarray to be Removed to Make Array SortedUnknown
- 1598.Crawler Log FolderEasy
- 1614.Maximum Nesting Depth of the ParenthesesEasy
- 1653.Minimum Deletions to Make String BalancedMedium
- 1700.Number of Students Unable to Eat LunchEasy
- 1717.Maximum Score From Removing SubstringsUnknown
- 1963.Minimum Number of Swaps to Make the String BalancedUnknown
- 2116.Check if a Parentheses String Can Be ValidMedium
- 2197.Replace Non-Coprime Numbers in ArrayUnknown
- 2211.Count Collisions on a RoadUnknown
- 2375.Construct Smallest Number From DI StringMedium
- 2434.Using a Robot to Print the Lexicographically Smallest StringMedium
- 2696.Minimum String Length After Removing SubstringsEasy
- 2751.Robot CollisionsUnknown
- 2818.Apply Operations to Maximize ScoreUnknown
- 2940.Find Building Where Alice and Bob Can MeetUnknown
- 3170.Lexicographically Minimum String After Removing StarsUnknown
- 3228.Maximum Number of Operations to Move Ones to the EndUnknown