~/problems
Problems
Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.
Hash maps and counting
Counter/defaultdict, complement lookups, prefix-sum + hash map.
Main path: 8 problems, about 3 hours.
Notes
Recognise it when: you're counting, grouping, deduplicating, looking up a complement ("does target - x exist?"), or answering in O(1) what you've seen so far.
seen = {}
for i, x in enumerate(nums):
if target - x in seen: return [seen[target - x], i]
seen[x] = i
# subarrays summing to k: count prefix sums seen so far
count, prefix, seen = 0, 0, Counter({0: 1})
for x in nums:
prefix += x
count += seen[prefix - k]
seen[prefix] += 1
Counter,defaultdict(list)for grouping. Keys must be hashable:tuple(sorted(word))works, a list doesn't.- Seed with
{0: 1}for prefix-sum counting, so subarrays that start at index 0 are counted.
25 problems
Interview roadmap
Arrays & hashing Counting, lookups, sorting with keys, prefix sums.
Hash maps and counting guide
- Play first: The Monster Vault 1-minute game Hash map (buckets and chaining)
- Count with a dict, then look up basics py · c++ · java easy
- Coffee-shop loyalty stamps py · c++ · java easy
- Design HashMap code the boss py · c++ · java easy
- Valid Anagram py · c++ · java easy
- Two Sum ▶ boss game py · c++ · java easy
- Group Anagrams ▶ boss game py · c++ · java medium
- Longest Consecutive Sequence py · c++ · java medium
- First Missing Positive py · c++ · java hard
More practice: 17 problems
- Contains Duplicate py · c++ · java easy
- Longest Common Prefix py · c++ · java easy
- Account registration deduplication Airbnb py · c++ · java easy
- Full path of a folder Uber py · c++ · java easy
- Majority Element ▶ boss game py · c++ · java easy
- Percentage transfers between accounts Coinbase py · c++ · java easy
- Bloom Filter ▶ boss game py · c++ · java medium
- Compact prefixes of a permutation Uber py · c++ · java medium
- Valid Sudoku py · c++ · java medium
- Encode and Decode Strings py · c++ · java medium
- Are two nested sets the same? Pinterest py · c++ · java medium
- Turn a tick stream into table rows Jane Street py · c++ · java medium
- Detect Squares py · c++ · java medium
- Maximum Points on a Line py · c++ · java hard
- Sparse Matrix Operation assessment 2 levels OraclePinterest py · c++ · java medium
- Simplified git diff assessment 2 levels Jane Street py · c++ · java hard
- Merkle tree directory diff assessment 2 levels Cursor py · c++ · java medium