Two Pointers Pattern Hub
5 problems3Sum
mediumSort the array first (`O(N log N)`), fix anchor `nums[i]` (skipping duplicates and breaking early if `nums[i] > 0`), and run Two Pointers on `(i+1 .. N-1)` skipping duplicates on `l` after matches.
Container With Most Water
mediumStart with widest container `(l=0, r=n-1)`. Always move the SHORTER wall inward: advancing the taller wall can only shrink width while keeping height bounded by the untouched shorter wall.
Trapping Rain Water
hardWater above bar `i` equals `min(maxLeft, maxRight) - height[i]`. Using two pointers maintaining `leftMax` and `rightMax`, whenever `leftMax <= rightMax`, the right side is guaranteed >= `leftMax`, so water at `l` is finalized cleanly in O(1) space!
Two Sum II - Input Array Is Sorted
mediumSorted order guarantees monotonic sum adjustments: if `nums[l] + nums[r] > target`, only decreasing `r` can lower the sum; if `< target`, increment `l`. Return 1-based indices.
Valid Palindrome
easyConverging left/right pointers skipping non-alphanumeric characters, comparing lowercased chars in O(1) extra space without allocating filtered strings.