When to use: Sorted arrays, find pairs, or remove duplicates.
Simple Template:
left, right = 0, len(arr)-1
while left < right:
if condition(arr[left], arr[right]):
# found or move both
left += 1
right -= 1
elif too_small:
left += 1
else:
right -= 1
Interviewer:
Tell me if two numbers in a sorted array sum to target" (Two Sum II) or "Container With Most Water.
How to Answer:
Array is sorted, so two pointers from ends should work in O(n)
Show brute force first, then optimize. Practice: 3Sum, Remove Duplicates.
🔥 You will solve these in <15 mins next interview!