DSA question set · 190 questions
Stack DSA Practice Questions
Explore 190 DSA questions in Stack. Practice with DSAWiser’s code editor and visualizer.
StackStringsMonotonic StackTreeDepth-First SearchDynamic ProgrammingDequeMonotonic QueueUnion FindGraphSegment TreeGeometrySortingHeap
What’s in this set
The Stack collection contains 190 problems: 50 basic, 50 easy, 50 medium, 25 hard, 15 very hard. Choose a question at your current level, or follow the collection’s order below.
Topics in this collection include Stack, Strings, Monotonic Stack, Tree, Depth-First Search. Each question shows its own topics and difficulty so you can decide where to begin.
Practice with the code visualizer
- Open a question in the editor and read the statement, inputs, and expected output. Predict the result for a small example before writing code.
- Write a solution and run the examples. If a result differs from your prediction, reduce the input until you can follow each step.
- Step through your code in the visualizer. Use a breakpoint to inspect the state at a specific line, then compare it with your reasoning.
Questions in this set
190 totalOpen a question in the editor to read its statement and examples. Sign in to practice.
- Push and Pop Single ElementStackBasic
- Order of Removal (LIFO Principle)StackBasic
- Stack Size After OperationsStackBasic
- Top Element Inspection (Peek)StackBasic
- Is Stack Empty CheckStackBasic
- Bottom Element of a StackStackBasic
- Value of the Last PopStackBasic
- Reverse a String Using a StackStack · StringsBasic
- Stack Underflow DetectionStackBasic
- Peak Stack Depth (Maximum Size)StackBasic
- Sum of Stack ElementsStackBasic
- Count Elements Equal to Target in StackStackBasic
- Simulating Single Character BackspaceStackBasic
- Alternate Push and PopStackBasic
- Remove Top K ElementsStackBasic
- Clear Stack OperationStackBasic
- Check Matching Parentheses of Single TypeStack · StringsBasic
- Remove Adjacent Duplicates of Length 2StackBasic
- Stack Reversal into a Second StackStackBasic
- Top Equals Bottom ElementStackBasic
- Duplicate the Top ElementStackBasic
- Swap Top Two ElementsStackBasic
- Total Number of Pushes PerformedStackBasic
- Residual Elements in Single-Bracket StackStack · StringsBasic
- Stack Capacity Overflow CheckStackBasic
- Push Positive, Pop on NegativeStackBasic
- Peek at Second-from-Top ElementStackBasic
- Undo Typing OperationStack · StringsBasic
- Count Consecutive Identical Elements on TopStackBasic
- Push Batches and Peek TopStackBasic
- Two Stacks Equality CheckStackBasic
- Browser Back History SimulationStackBasic
- Push if Not Equal to TopStackBasic
- Element at Depth K from TopStackBasic
- Count Even and Odd Numbers in StackStackBasic
- Stack Checkpoint and RollbackStackBasic
- Maximum Element PoppedStackBasic
- Reverse Words in a Sentence Using a Word StackStackBasic
- Minimum Element in StackStackBasic
- Check if Element Exists in StackStackBasic
- Two Independent Stacks SimulationStackBasic
- Filter Even Elements into New StackStackBasic
- Stack Palindrome CheckStackBasic
- Count Operations Until EmptyStackBasic
- Pop and Discard Until TargetStackBasic
- Stack Prefix BalanceStackBasic
- Strip Target Elements from TopStackBasic
- Invert Sign of Top ElementStackBasic
- Compare Tops of Two StacksStackBasic
- Count Pushes While Stack Exceeds ThresholdStackBasic
- Valid Parentheses with Multiple Bracket TypesStack · StringsEasy
- Min Stack DesignStackEasy
- Evaluate Reverse Polish Notation (Basic Operators)Stack · StringsEasy
- Backspace String CompareStack · StringsEasy
- Crawler Log FolderStackEasy
- Make The String GreatStack · StringsEasy
- Baseball GameStackEasy
- Remove Outermost ParenthesesStack · StringsEasy
- Maximum Nesting Depth of ParenthesesStack · StringsEasy
- Implement Queue using StacksStackEasy
- Final Prices With a Special Discount in a ShopStackEasy
- Build an Array With Stack OperationsStackEasy
- Remove All Adjacent Duplicates in StringStack · StringsEasy
- Clear DigitsStack · StringsEasy
- Count Students Unable to Eat LunchStackEasy
- Next Greater Element IStack · Monotonic StackEasy
- Reverse Prefix of WordStack · StringsEasy
- Delete Middle Element of a StackStackEasy
- Sort a Stack Using an Auxiliary StackStackEasy
- Check If Word Is Valid After SubstitutionsStackEasy
- Minimum Add to Make Parentheses ValidStack · StringsEasy
- Max Stack DesignStackEasy
- Implement Stack using QueuesStackEasy
- Validate Markup Tag PairsStack · StringsEasy
- Remove Consecutive Duplicate Numbers IIStackEasy
- Daily Temperatures (Wait Days for Warmer Weather)Stack · Monotonic StackEasy
- Normalize Folder Path from TokensStackEasy
- Sum of Depths for Matched Parentheses PairsStack · StringsEasy
- Reverse Only Letters Using StackStack · StringsEasy
- Undo and Redo Text BufferStack · StringsEasy
- Simple Bracket String ExpanderStack · StringsEasy
- Validate Stack SequencesStackEasy
- Daily Stock SpanStack · Monotonic StackEasy
- Minimum Swaps to Make Parentheses BalancedStack · StringsEasy
- Asteroid CollisionStackEasy
- Longest Valid Parentheses PrefixStack · StringsEasy
- Minimum Remove to Make Valid ParenthesesStack · StringsEasy
- Next Smaller Element to the RightStack · Monotonic StackEasy
- Previous Greater Element to the LeftStack · Monotonic StackEasy
- Evaluate Prefix (Polish) NotationStack · StringsEasy
- Removing Stars From a StringStack · StringsEasy
- Previous Smaller Element to the LeftStack · Monotonic StackEasy
- Opposite Parity Cancellation StackStackEasy
- Reverse a Stack Using Function RecursionStackEasy
- Balanced Brackets Embedded in ProseStack · StringsEasy
- Check for Redundant ParenthesesStack · StringsEasy
- Count Total Adjacent Duplicate Pairs CancelledStackEasy
- Iterative Preorder Traversal Using StackStack · Tree · Depth-First SearchEasy
- Construct Monotonic Strictly Increasing StackStack · Monotonic StackEasy
- Prioritized Substring Pair EliminationStack · StringsEasy
- Simplify Canonical Unix PathStackMedium
- Decode Nested StringStack · StringsMedium
- Remove Duplicate Letters (Smallest Subsequence)Stack · StringsMedium
- Next Greater Element II (Circular Array)Stack · Monotonic StackMedium
- Basic Calculator II (Multiplication and Division Precedence)Stack · StringsMedium
- Remove K DigitsStack · StringsMedium
- 132 PatternStackMedium
- Score of ParenthesesStack · StringsMedium
- Reverse Substrings Between Each Pair of ParenthesesStack · StringsMedium
- Design a Stack With Increment OperationStackMedium
- Sum of Subarray MinimumsStack · Monotonic StackMedium
- Car FleetStackMedium
- Remove All Adjacent Duplicates in String II (K-Duplicates)Stack · StringsMedium
- Maximum Frequency Stack (FreqStack)StackMedium
- Streaming Stock SpannerStack · Monotonic StackMedium
- Sum of Subarray RangesStack · Monotonic StackMedium
- Number of Visible People in a QueueStackMedium
- Flatten Nested List IteratorStackMedium
- Find the Most Competitive SubsequenceStack · Monotonic StackMedium
- Minimum Deletions to Make String BalancedStack · StringsMedium
- Minimum Insertions to Balance a Parentheses String (Double Right Brackets)Stack · StringsMedium
- Ternary Expression ParserStack · StringsMedium
- Check if a Parentheses String Can Be ValidStack · StringsMedium
- Maximum Width RampStack · Monotonic StackMedium
- Parsing A Boolean ExpressionStackMedium
- Steps to Make Array Non-decreasingStackMedium
- Beautiful Towers (Maximum Mountain Sum)Stack · Monotonic StackMedium
- Maximum Binary Tree Construction (Cartesian Tree)Stack · Monotonic Stack · Tree · Depth-First SearchMedium
- Exclusive Time of FunctionsStackMedium
- Clumsy FactorialStackMedium
- Longest Well-Performing IntervalStackMedium
- Minimum Cost Tree From Leaf ValuesStack · Tree · Depth-First SearchMedium
- Subarray With Elements Greater Than Varying ThresholdStackMedium
- Mini Parser for Nested IntegersStack · StringsMedium
- Next Greater Permutation (Next Greater Element III)Stack · Monotonic StackMedium
- Count Submatrices With All OnesStackMedium
- Verify Preorder Sequence in Binary Search TreeStack · Tree · Depth-First SearchMedium
- Infix Expression Evaluation with Operator PrecedenceStackMedium
- Maximum Score From Removing SubstringsStack · StringsMedium
- Number of Valid SubarraysStackMedium
- Longest Absolute File PathStackMedium
- Maximum Subarray Min-ProductStack · Monotonic StackMedium
- Shortest Unsorted Continuous SubarrayStackMedium
- Find Lexicographically Smallest Permutation (DI Sequence)StackMedium
- Minimum Operations to Form Target ArrayStackMedium
- Valid Parenthesis String with Wildcard AsterisksStack · StringsMedium
- Next Greater Node in Linked ListStack · Monotonic StackMedium
- Binary Search Tree Iterator (Controlled Inorder Stack)Stack · Tree · Depth-First SearchMedium
- Decoded String at Index (Virtual Unwinding)Stack · StringsMedium
- Maximum Nesting Depth Split (Two Balanced Subsequences)StackMedium
- Largest Rectangle in HistogramStack · Monotonic StackHard
- Maximal Rectangle in Binary MatrixStackHard
- Trapping Rain Water (Stack-Based Basin Accumulation)StackHard
- Longest Valid Parentheses SubstringStack · StringsHard
- Basic Calculator (Parentheses and Unary Negation)Stack · StringsHard
- Number of Atoms (Chemical Formula Parser)Stack · StringsHard
- Basic Calculator III (Full Precedence with Parentheses)Stack · StringsHard
- Robot CollisionsStackHard
- Create Maximum Number from Two ArraysStackHard
- Car Fleet II (Collision Times)StackHard
- Sum of Total Strength of WizardsStack · Monotonic StackHard
- Tag ValidatorStack · StringsHard
- Dinner Plate StacksStackHard
- Maximum Score of a Good SubarrayStack · Monotonic StackHard
- Parse Lisp Expression (Scoped Environment Stack)StackHard
- Apply Operations to Maximize Score (Prime Score Monotonic Bounds)Stack · Monotonic Stack · Dynamic ProgrammingHard
- Constrained Subsequence SumStack · Deque · Monotonic Queue · Dynamic ProgrammingHard
- Odd Even Jump (Dual Monotonic Stacks on Sorted Indices)Stack · Monotonic StackHard
- Shortest Subarray with Sum at Least KStack · Deque · Monotonic QueueHard
- Stamping The Sequence (Reverse Execution Stack)StackHard
- Find Building Where Alice and Bob Can MeetStackHard
- Brace Expansion II (Set Algebra Stack Parser)Stack · StringsHard
- Max Chunks To Make Sorted II (Chunk-Collapsing Stack)Stack · Monotonic StackHard
- Minimum Difficulty of a Job Schedule (Monotonic Stack DP Acceleration)Stack · Monotonic Stack · Dynamic ProgrammingHard
- Maximal Rectangle with Column PermutationsStackHard
- Disjoint-Set Union with Explicit Rollback Stack (Offline Dynamic Connectivity)Stack · Union Find · GraphVery hard
- Maximal 3D Sub-Cuboid of All OnesStackVery hard
- Sum of Subarray (Minimum × Maximum) with Monotonic StructuresStack · Monotonic Stack · Dynamic ProgrammingVery hard
- Convex Hull Trick via Monotonic Line StackStack · Monotonic Stack · Dynamic ProgrammingVery hard
- Lexical Macro Expander with Parameter Substitution StackStack · StringsVery hard
- Append-Only Cartesian Tree Spine and Range Minimum QueriesStack · Monotonic Stack · Tree · Depth-First Search · Segment TreeVery hard
- Count of Monotonically Bounded Matrix BasinsStack · Monotonic StackVery hard
- Persistent Monotonic Stack (Historical Next Greater Element)Stack · Monotonic StackVery hard
- Monotonic Ancestor Stack on Tree PathsStack · Monotonic Stack · Tree · Depth-First SearchVery hard
- Convex Hull Monotone Chain Stack with Inscribed Triangle OptimizationStack · Geometry · SortingVery hard
- Virtual Tree (Auxiliary Tree) Construction via Monotonic StackStack · Monotonic Stack · Tree · Depth-First SearchVery hard
- Slope Trick: Minimum L1 Penalty Smoothing via Derivative StacksStack · Dynamic Programming · HeapVery hard
- Maximum Histogram Area with One Height ModificationStack · Monotonic Stack · Segment TreeVery hard
- Offline Dynamic Connectivity via Time Segment Tree and Rollback StackStack · Tree · Depth-First Search · Union Find · Graph · Segment TreeVery hard
- Ambiguous Dynamic-Arity Expression Tree CountingStack · Tree · Depth-First Search · Dynamic ProgrammingVery hard