Stacks
Last-in, first-out collection for undo, parsing, and nested work.
Stacks Practice Problems
Easy
4 problems- 340easy
Valid Parentheses
Use a stack to check that every opening bracket is closed by the matching closing bracket in the right order.
- 341easy
Min Stack
Build a stack that also reports its smallest value instantly, by storing a running minimum beside every pushed value.
- 342easy
Baseball Game
Keep a score record on a stack, where each operation records, cancels, doubles or sums the most recent scores.
- 343easy
Remove All Adjacent Duplicates In String
Cancel equal neighbouring letters in one pass by popping the stack whenever the next letter matches the top.
Medium
4 problems- 344medium
Evaluate Reverse Polish Notation
Evaluate an expression where operators come after their numbers, by pushing numbers and folding each operator into one result.
- 345medium
Decode String
Expand nested k[text] patterns using two stacks that park the repeat count and the text built before each bracket.
- 346medium
Asteroid Collision
Track surviving asteroids on a stack, where each left-moving asteroid fights the top until one of them is destroyed.
- 347medium
Simplify Path
Turn a Unix file path into its canonical form by pushing folder names and popping one off for every ".." part.
Hard
2 problems- 348hard
Basic Calculator
Evaluate a sum with brackets by parking the running result and the current sign on a stack whenever a bracket opens.
- 349hard
Largest Rectangle In Histogram
Find the biggest rectangle under a row of bars with a monotonic stack that measures each bar as soon as a shorter one arrives.
Related concepts
| Topic | Description |
|---|---|
| Arrays | Ordered indexable collection for O(1) access by position. |
| Linked Lists | Nodes linked by pointers — insert and delete without shifting a contiguous block. |
| Queues | First-in, first-out collection for scheduling, BFS, and buffering. |
| Hash Tables | Key-to-value lookup in average O(1) via hashing into buckets. |
| Trees | Hierarchical nodes with parent–child links for ordered and nested data. |
| Heaps | Priority queue backed by a binary heap for fast min or max access. |