Pattern Recognition Drill
Easy Hash Maps
The Problem
Given unsorted array a and target t, return indices of the pair that sums to t.
What approach would you use?
Think about it before scrolling down.
For each element x, check if (target - x) is in the map. Insert x after checking. O(n).
Sort + two pointers is O(n log n) but loses original indices — need extra bookkeeping.
Common Trap
Brute force O(n²) checks all pairs. The hash map complement lookup is the key insight.