Stacks for Matching Brackets
Validate parentheses with a stack.
Last In, First Out
A stack is a pile where the last item you add is the first one you remove, just like stacking plates. 🍽️
Python Lists Are Stacks
In Python you do not need a special class. A plain list already works as a fast, ready-made stack for contests.
stack = []All lessons in this course
- Stacks for Matching Brackets
- Monotonic Stack: Next Greater Element
- Queues and collections.deque
- Sliding Window Maximum with Deque