Data Structures19 sections · 729 units
Open in Course

Recognizing Hash Problems

Pattern signals

Look for these signals:

1.1. "Find two elements with property X": complement lookup (two-sum pattern)

2.2. "Count occurrences" or "frequency": frequency counting

3.3. "Group by equivalence": custom keys (group anagrams)

4.4. "Subarray with sum/property": prefix sum + hash map

5.5. "Check if seen before": hash set

6.6. "Fast lookup needed": hash map

When you see O(n2)O(n^2) brute force and ask "can I do better?", hash tables are often the answer.