Skip to main content

πŸ“š Stack

Stacks shine when you need to "remember the last thing" β€” matching brackets, evaluating expressions, finding the next greater element. The monotonic stack is the highest-leverage pattern here.

This category contains 9 problems. Use the patterns below to recognize what's being asked, then jump to the problem list at the bottom.


🧠 Key Patterns​

  • Bracket Matching / Validation β€” Push opens, pop & compare on close.
  • Monotonic Stack β€” Next greater/smaller element. O(n)O(n) amortized.
  • Expression Evaluation β€” Shunting yard, postfix evaluation.
  • Min/Max Stack β€” Auxiliary stack tracking running min/max.
  • Simulating Recursion β€” Iterative DFS, in-order without recursion.

⚠️ Common Pitfalls​

  • Forgetting to flush remaining elements after the main loop (e.g. unmatched brackets).
  • Monotonic stack: choosing wrong comparison direction.

πŸ“š Study Resources​

πŸ“Ί Videos​

πŸ“– Books​

  • Algorithms β€” Sedgewick β€” Ch. 1.3

🌐 Articles & References​


πŸ’» All Stack Problems​