Stack Cheat Sheet
Quick reference for coding interviews. Bookmark this page!
What is Stack?
Understand LIFO data structure and its applications in parsing and backtracking.
Trigger Words
When you see these in a problem, think Stack:
Template Code
def isValid(s: str) -> bool:
stack = []
mapping = {')': '(', '}': '{', ']': '['}
for char in s:
if char in mapping: # Closing bracket
if not stack or stack[-1] != mapping[char]:
return False
stack.pop()
else: # Opening bracket
stack.append(char)
return len(stack) == 0
Complexity
| Typical Time | O(n) |
|---|---|
| Typical Space | O(n) |
Common Variations
- Basic Stack
- Stack with constraints
- Optimized Stack
Practice Problems
See all Stack problems →Practice Stack
Learn to recognize patterns instantly with interactive MCQs.
Download LeetEye Free