Coding Problems List
This is a curated list of coding problems I’ve worked on, with key insights and common mistakes I made.
Problems Completed
Two Sum
Tags: #array #hashtable #twopointer
Status: ✅ Completed
Key Insight: Hash Map for O(1) complement lookup. Demonstrates efficient Time-Space Trade-off.
Permutations
Tags: #backtracking #recursion #array
Status: ✅ Completed
Key Insight: Classic backtracking pattern with proper base case handling.
Common Mistake: ⚠️ Return condition error - I was returning [] (empty list) instead of [[]] (list containing empty list) for the base case when nums is empty. The base case should return a list containing one permutation (the empty permutation), not an empty list of permutations.
Correct Base Case Logic:
def permute(nums):
if not nums:
return [[]] # ✅ One empty permutation
# NOT return [] # ❌ Zero permutationsRationale: When nums = [], there is exactly one permutation of an empty list: the empty permutation []. So we return [[]] (a list containing that one permutation). This enables the recursive multiplication to work correctly.
Problems Queue
- 3Sum
- Combination Sum
- Subsets
- Word Search
Key Patterns & Insights
Backtracking Problems
- Base Case Pattern: Always consider what the “one valid result” should be for the simplest input
- Common Error: Confusing “no results” vs “one empty result” in base cases
- Template:
def backtrack(path, remaining): if not remaining: # base case return [path] # one result containing current path # recursive case
Time-Space Trade-offs
- Hash Maps: O(1) lookup but O(N) space
- Two Pointers: O(1) space but requires sorted input
- Consider both approaches for complement/pair finding problems
Common Mistake Categories
- Base Case Logic: Especially in recursive/backtracking problems
- Off-by-one Errors: Array indexing and loop bounds
- Edge Cases: Empty inputs, single elements, duplicates
- Time Complexity: Not optimizing from brute force when possible