| Pattern | Pointers Start | Movement | Classic Problems |
|---|---|---|---|
| Opposite Ends | Start and end | Move toward each other | Two Sum (sorted), Container With Water |
| Same Direction | Both at start | One fast, one slow | Remove duplicates, Merge arrays |
| Fast & Slow | Both at start | Different speeds | Cycle detection, Find middle |
| Signal | Pattern |
|---|---|
| Sorted array + find pair | Opposite ends |
| Palindrome check | Opposite ends |
| In-place array modification | Same direction (slow/fast) |
| Merging sorted arrays | Same direction |
| Linked list cycle | Fast & slow |
| Find middle of list | Fast & slow |
| Reduce O(n²) to O(n) | Usually opposite ends |
| Two Pointers | Sliding Window | |
|---|---|---|
| Goal | Find pair/triplet satisfying condition | Find subarray satisfying condition |
| Typical movement | Toward each other or same direction | Always same direction (right expands) |
| Data usually | Sorted | Not necessarily sorted |
| Example | Two Sum in sorted array | Longest substring without repeats |
| Pattern | Time | Space |
|---|---|---|
| Opposite ends | O(n) | O(1) |
| Same direction | O(n) | O(1) |
| Fast & slow | O(n) | O(1) |
| 3Sum (with sorting) | O(n²) | O(1) |