Backtracking Cheat Sheet
Quick reference for coding interviews. Bookmark this page!
What is Backtracking?
Explore all possibilities with systematic trial and error.
Trigger Words
When you see these in a problem, think Backtracking:
Template Code
def subsets(nums: List[int]) -> List[List[int]]:
result = []
def backtrack(start, current):
result.append(current[:])
for i in range(start, len(nums)):
current.append(nums[i])
backtrack(i + 1, current)
current.pop()
backtrack(0, [])
return result
Complexity
| Typical Time | O(n * 2^n) |
|---|---|
| Typical Space | O(n) |
Common Variations
- Basic Backtracking
- Backtracking with constraints
- Optimized Backtracking
Practice Problems
See all Backtracking problems →Practice Backtracking
Learn to recognize patterns instantly with interactive MCQs.
Download LeetEye Free