Stack Algorithms
LIFO operations and stack-based solutions
Stack - Complete Guide
Stack: Master the Fundamentals
A stack is a LIFO (last-in, first-out) data structure. It appears in parsing, expression evaluation, backtracking, and many interview problems. This guide covers stack basics and the main patterns; each concept links to a detailed page.
What Is a Stack?
Operations: push (add on top), pop (remove from top), peek/top (read top). Optional: isEmpty, size. All in O(1) when implemented with an array or linked list. Use a stack when you need to process elements in reverse order of arrival or to match pairs (e.g. brackets).
Core Concepts
1. Stack Basics
Learn more: Stack Basics (LIFO, Operations) โ
2. Valid Parentheses
Learn more: Valid Parentheses โ
3. Min Stack
Learn more: Min Stack / Max Stack โ
4. Monotonic Stack
Learn more: Monotonic Stack โ
5. Next Greater Element
Learn more: Next Greater Element โ
6. Daily Temperatures
Learn more: Daily Temperatures โ
7. Largest Rectangle in Histogram
Learn more: Largest Rectangle in Histogram โ
8. Decode String
Learn more: Decode String โ
9. Queue using Stacks
Learn more: Implement Queue using Stacks โ
10. Remove Adjacent Duplicates
Learn more: Remove All Adjacent Duplicates โ
11. Score of Parentheses
Learn more: Score of Parentheses โ
12. Asteroid Collision
Learn more: Asteroid Collision โ
13. Simplify Path
Learn more: Simplify Path โ
14. Basic Calculator
Learn more: Basic Calculator โ
15. Remove K Digits
Learn more: Remove K Digits โ
16. Design Stack
Learn more: Design Stack โ
Learning Path
Start with: Stack Basics, Valid Parentheses, Min Stack.
Then: Monotonic Stack, Next Greater Element, Daily Temperatures, Largest Rectangle in Histogram.
Advanced: Decode String, Basic Calculator, Remove K Digits.
Summary
Stack problems often involve matching pairs (parentheses), monotonic stacks (next greater/smaller), or parsing (decode string, calculator). Use the concept links above for detailed guides and examples.