Two pointer technique masterclass - all patterns in one place
Two pointers is probably the most versatile technique. Here's every pattern I've seen:
Opposite ends:
- Two sum (sorted array)
- Container with most water
- Valid palindrome
- 3Sum / 4Sum
Same direction (fast/slow):
- Remove duplicates from sorted array
- Linked list cycle detection
- Move zeroes
- Remove element
Merge pattern:
- Merge sorted arrays
- Intersection of two arrays
- Merge intervals (sort + pointer)
The key insight: if the problem involves a sorted array/list and mentions O(1) space, think two pointers first.