Pattern Recognition Drill
Easy Arrays & Strings
The Problem
Given sorted 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.
Start from both ends. If sum < target, move left up; if sum > target, move right down. O(n).
Works (O(n)) but wastes the sorted property. Interviewer wants you to use the sort.
Common Trap
Binary search for each element is O(n log n) — works but two pointers is cleaner and O(n).