DSAWiser

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

  1. Open a question in the editor and read the statement, inputs, and expected output. Predict the result for a small example before writing code.
  2. Write a solution and run the examples. If a result differs from your prediction, reduce the input until you can follow each step.
  3. 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 total

Open a question in the editor to read its statement and examples. Sign in to practice.

  1. Push and Pop Single ElementStackBasic
  2. Order of Removal (LIFO Principle)StackBasic
  3. Stack Size After OperationsStackBasic
  4. Top Element Inspection (Peek)StackBasic
  5. Is Stack Empty CheckStackBasic
  6. Bottom Element of a StackStackBasic
  7. Value of the Last PopStackBasic
  8. Reverse a String Using a StackStack · StringsBasic
  9. Stack Underflow DetectionStackBasic
  10. Peak Stack Depth (Maximum Size)StackBasic
  11. Sum of Stack ElementsStackBasic
  12. Count Elements Equal to Target in StackStackBasic
  13. Simulating Single Character BackspaceStackBasic
  14. Alternate Push and PopStackBasic
  15. Remove Top K ElementsStackBasic
  16. Clear Stack OperationStackBasic
  17. Check Matching Parentheses of Single TypeStack · StringsBasic
  18. Remove Adjacent Duplicates of Length 2StackBasic
  19. Stack Reversal into a Second StackStackBasic
  20. Top Equals Bottom ElementStackBasic
  21. Duplicate the Top ElementStackBasic
  22. Swap Top Two ElementsStackBasic
  23. Total Number of Pushes PerformedStackBasic
  24. Residual Elements in Single-Bracket StackStack · StringsBasic
  25. Stack Capacity Overflow CheckStackBasic
  26. Push Positive, Pop on NegativeStackBasic
  27. Peek at Second-from-Top ElementStackBasic
  28. Undo Typing OperationStack · StringsBasic
  29. Count Consecutive Identical Elements on TopStackBasic
  30. Push Batches and Peek TopStackBasic
  31. Two Stacks Equality CheckStackBasic
  32. Browser Back History SimulationStackBasic
  33. Push if Not Equal to TopStackBasic
  34. Element at Depth K from TopStackBasic
  35. Count Even and Odd Numbers in StackStackBasic
  36. Stack Checkpoint and RollbackStackBasic
  37. Maximum Element PoppedStackBasic
  38. Reverse Words in a Sentence Using a Word StackStackBasic
  39. Minimum Element in StackStackBasic
  40. Check if Element Exists in StackStackBasic
  41. Two Independent Stacks SimulationStackBasic
  42. Filter Even Elements into New StackStackBasic
  43. Stack Palindrome CheckStackBasic
  44. Count Operations Until EmptyStackBasic
  45. Pop and Discard Until TargetStackBasic
  46. Stack Prefix BalanceStackBasic
  47. Strip Target Elements from TopStackBasic
  48. Invert Sign of Top ElementStackBasic
  49. Compare Tops of Two StacksStackBasic
  50. Count Pushes While Stack Exceeds ThresholdStackBasic
  51. Valid Parentheses with Multiple Bracket TypesStack · StringsEasy
  52. Min Stack DesignStackEasy
  53. Evaluate Reverse Polish Notation (Basic Operators)Stack · StringsEasy
  54. Backspace String CompareStack · StringsEasy
  55. Crawler Log FolderStackEasy
  56. Make The String GreatStack · StringsEasy
  57. Baseball GameStackEasy
  58. Remove Outermost ParenthesesStack · StringsEasy
  59. Maximum Nesting Depth of ParenthesesStack · StringsEasy
  60. Implement Queue using StacksStackEasy
  61. Final Prices With a Special Discount in a ShopStackEasy
  62. Build an Array With Stack OperationsStackEasy
  63. Remove All Adjacent Duplicates in StringStack · StringsEasy
  64. Clear DigitsStack · StringsEasy
  65. Count Students Unable to Eat LunchStackEasy
  66. Next Greater Element IStack · Monotonic StackEasy
  67. Reverse Prefix of WordStack · StringsEasy
  68. Delete Middle Element of a StackStackEasy
  69. Sort a Stack Using an Auxiliary StackStackEasy
  70. Check If Word Is Valid After SubstitutionsStackEasy
  71. Minimum Add to Make Parentheses ValidStack · StringsEasy
  72. Max Stack DesignStackEasy
  73. Implement Stack using QueuesStackEasy
  74. Validate Markup Tag PairsStack · StringsEasy
  75. Remove Consecutive Duplicate Numbers IIStackEasy
  76. Daily Temperatures (Wait Days for Warmer Weather)Stack · Monotonic StackEasy
  77. Normalize Folder Path from TokensStackEasy
  78. Sum of Depths for Matched Parentheses PairsStack · StringsEasy
  79. Reverse Only Letters Using StackStack · StringsEasy
  80. Undo and Redo Text BufferStack · StringsEasy
  81. Simple Bracket String ExpanderStack · StringsEasy
  82. Validate Stack SequencesStackEasy
  83. Daily Stock SpanStack · Monotonic StackEasy
  84. Minimum Swaps to Make Parentheses BalancedStack · StringsEasy
  85. Asteroid CollisionStackEasy
  86. Longest Valid Parentheses PrefixStack · StringsEasy
  87. Minimum Remove to Make Valid ParenthesesStack · StringsEasy
  88. Next Smaller Element to the RightStack · Monotonic StackEasy
  89. Previous Greater Element to the LeftStack · Monotonic StackEasy
  90. Evaluate Prefix (Polish) NotationStack · StringsEasy
  91. Removing Stars From a StringStack · StringsEasy
  92. Previous Smaller Element to the LeftStack · Monotonic StackEasy
  93. Opposite Parity Cancellation StackStackEasy
  94. Reverse a Stack Using Function RecursionStackEasy
  95. Balanced Brackets Embedded in ProseStack · StringsEasy
  96. Check for Redundant ParenthesesStack · StringsEasy
  97. Count Total Adjacent Duplicate Pairs CancelledStackEasy
  98. Iterative Preorder Traversal Using StackStack · Tree · Depth-First SearchEasy
  99. Construct Monotonic Strictly Increasing StackStack · Monotonic StackEasy
  100. Prioritized Substring Pair EliminationStack · StringsEasy
  101. Simplify Canonical Unix PathStackMedium
  102. Decode Nested StringStack · StringsMedium
  103. Remove Duplicate Letters (Smallest Subsequence)Stack · StringsMedium
  104. Next Greater Element II (Circular Array)Stack · Monotonic StackMedium
  105. Basic Calculator II (Multiplication and Division Precedence)Stack · StringsMedium
  106. Remove K DigitsStack · StringsMedium
  107. 132 PatternStackMedium
  108. Score of ParenthesesStack · StringsMedium
  109. Reverse Substrings Between Each Pair of ParenthesesStack · StringsMedium
  110. Design a Stack With Increment OperationStackMedium
  111. Sum of Subarray MinimumsStack · Monotonic StackMedium
  112. Car FleetStackMedium
  113. Remove All Adjacent Duplicates in String II (K-Duplicates)Stack · StringsMedium
  114. Maximum Frequency Stack (FreqStack)StackMedium
  115. Streaming Stock SpannerStack · Monotonic StackMedium
  116. Sum of Subarray RangesStack · Monotonic StackMedium
  117. Number of Visible People in a QueueStackMedium
  118. Flatten Nested List IteratorStackMedium
  119. Find the Most Competitive SubsequenceStack · Monotonic StackMedium
  120. Minimum Deletions to Make String BalancedStack · StringsMedium
  121. Minimum Insertions to Balance a Parentheses String (Double Right Brackets)Stack · StringsMedium
  122. Ternary Expression ParserStack · StringsMedium
  123. Check if a Parentheses String Can Be ValidStack · StringsMedium
  124. Maximum Width RampStack · Monotonic StackMedium
  125. Parsing A Boolean ExpressionStackMedium
  126. Steps to Make Array Non-decreasingStackMedium
  127. Beautiful Towers (Maximum Mountain Sum)Stack · Monotonic StackMedium
  128. Maximum Binary Tree Construction (Cartesian Tree)Stack · Monotonic Stack · Tree · Depth-First SearchMedium
  129. Exclusive Time of FunctionsStackMedium
  130. Clumsy FactorialStackMedium
  131. Longest Well-Performing IntervalStackMedium
  132. Minimum Cost Tree From Leaf ValuesStack · Tree · Depth-First SearchMedium
  133. Subarray With Elements Greater Than Varying ThresholdStackMedium
  134. Mini Parser for Nested IntegersStack · StringsMedium
  135. Next Greater Permutation (Next Greater Element III)Stack · Monotonic StackMedium
  136. Count Submatrices With All OnesStackMedium
  137. Verify Preorder Sequence in Binary Search TreeStack · Tree · Depth-First SearchMedium
  138. Infix Expression Evaluation with Operator PrecedenceStackMedium
  139. Maximum Score From Removing SubstringsStack · StringsMedium
  140. Number of Valid SubarraysStackMedium
  141. Longest Absolute File PathStackMedium
  142. Maximum Subarray Min-ProductStack · Monotonic StackMedium
  143. Shortest Unsorted Continuous SubarrayStackMedium
  144. Find Lexicographically Smallest Permutation (DI Sequence)StackMedium
  145. Minimum Operations to Form Target ArrayStackMedium
  146. Valid Parenthesis String with Wildcard AsterisksStack · StringsMedium
  147. Next Greater Node in Linked ListStack · Monotonic StackMedium
  148. Binary Search Tree Iterator (Controlled Inorder Stack)Stack · Tree · Depth-First SearchMedium
  149. Decoded String at Index (Virtual Unwinding)Stack · StringsMedium
  150. Maximum Nesting Depth Split (Two Balanced Subsequences)StackMedium
  151. Largest Rectangle in HistogramStack · Monotonic StackHard
  152. Maximal Rectangle in Binary MatrixStackHard
  153. Trapping Rain Water (Stack-Based Basin Accumulation)StackHard
  154. Longest Valid Parentheses SubstringStack · StringsHard
  155. Basic Calculator (Parentheses and Unary Negation)Stack · StringsHard
  156. Number of Atoms (Chemical Formula Parser)Stack · StringsHard
  157. Basic Calculator III (Full Precedence with Parentheses)Stack · StringsHard
  158. Robot CollisionsStackHard
  159. Create Maximum Number from Two ArraysStackHard
  160. Car Fleet II (Collision Times)StackHard
  161. Sum of Total Strength of WizardsStack · Monotonic StackHard
  162. Tag ValidatorStack · StringsHard
  163. Dinner Plate StacksStackHard
  164. Maximum Score of a Good SubarrayStack · Monotonic StackHard
  165. Parse Lisp Expression (Scoped Environment Stack)StackHard
  166. Apply Operations to Maximize Score (Prime Score Monotonic Bounds)Stack · Monotonic Stack · Dynamic ProgrammingHard
  167. Constrained Subsequence SumStack · Deque · Monotonic Queue · Dynamic ProgrammingHard
  168. Odd Even Jump (Dual Monotonic Stacks on Sorted Indices)Stack · Monotonic StackHard
  169. Shortest Subarray with Sum at Least KStack · Deque · Monotonic QueueHard
  170. Stamping The Sequence (Reverse Execution Stack)StackHard
  171. Find Building Where Alice and Bob Can MeetStackHard
  172. Brace Expansion II (Set Algebra Stack Parser)Stack · StringsHard
  173. Max Chunks To Make Sorted II (Chunk-Collapsing Stack)Stack · Monotonic StackHard
  174. Minimum Difficulty of a Job Schedule (Monotonic Stack DP Acceleration)Stack · Monotonic Stack · Dynamic ProgrammingHard
  175. Maximal Rectangle with Column PermutationsStackHard
  176. Disjoint-Set Union with Explicit Rollback Stack (Offline Dynamic Connectivity)Stack · Union Find · GraphVery hard
  177. Maximal 3D Sub-Cuboid of All OnesStackVery hard
  178. Sum of Subarray (Minimum × Maximum) with Monotonic StructuresStack · Monotonic Stack · Dynamic ProgrammingVery hard
  179. Convex Hull Trick via Monotonic Line StackStack · Monotonic Stack · Dynamic ProgrammingVery hard
  180. Lexical Macro Expander with Parameter Substitution StackStack · StringsVery hard
  181. Append-Only Cartesian Tree Spine and Range Minimum QueriesStack · Monotonic Stack · Tree · Depth-First Search · Segment TreeVery hard
  182. Count of Monotonically Bounded Matrix BasinsStack · Monotonic StackVery hard
  183. Persistent Monotonic Stack (Historical Next Greater Element)Stack · Monotonic StackVery hard
  184. Monotonic Ancestor Stack on Tree PathsStack · Monotonic Stack · Tree · Depth-First SearchVery hard
  185. Convex Hull Monotone Chain Stack with Inscribed Triangle OptimizationStack · Geometry · SortingVery hard
  186. Virtual Tree (Auxiliary Tree) Construction via Monotonic StackStack · Monotonic Stack · Tree · Depth-First SearchVery hard
  187. Slope Trick: Minimum L1 Penalty Smoothing via Derivative StacksStack · Dynamic Programming · HeapVery hard
  188. Maximum Histogram Area with One Height ModificationStack · Monotonic Stack · Segment TreeVery hard
  189. Offline Dynamic Connectivity via Time Segment Tree and Rollback StackStack · Tree · Depth-First Search · Union Find · Graph · Segment TreeVery hard
  190. Ambiguous Dynamic-Arity Expression Tree CountingStack · Tree · Depth-First Search · Dynamic ProgrammingVery hard