Two Pointer
3 programs — patterns, complexity, and code
| # | Program Name | Pattern | Time | Space | Key Idea | Level |
|---|---|---|---|---|---|---|
| 1 | validPalindrome | Two Pointer | O(n) | O(1) | Move left and right pointers inward, skipping non-alphanumerics. | Simple |
| 2 | threeSum | Sort + Two Pointer | O(n²) | O(1) | Sort array, then fix one element and use two-pointer on the rest. | Middle |
| 3 | containerWithMostWater | Two Pointer | O(n) | O(1) | Always move the shorter side inward to find a potentially taller boundary. | Middle |