Two pointers works on sorted arrays/strings where you walk inward from both ends to find pairs, triplets, or palindromes in O(N). A hashmap also gives O(N) but with O(N) memory. Two-pointer is preferred when memory is tight or when the array is sorted (e.g., “two sum in a sorted array”).
Two sum sorted: left=0, right=n-1; if sum > target right—; if sum < target left++.
Three sum: sort first, fix one i and two-pointer the rest, skip duplicates.
Container with most water: maximize area(left, right) * (right-left) greedily.
sorted arr [a..b..c..z]
L-> <-R result
Two pointers when the array is sorted and O(1) extra space matters.