Patterns
TP · Pattern 02
Two Pointers
Use two indices that move toward each other or in the same direction to solve problems on sorted arrays or when looking for pairs/triplets that satisfy a condition.
- Time
- O(n)
- Space
- O(1)
Spot it when
- Sorted array with pair/triplet sum problem
- Remove duplicates in-place
- Palindrome check
- Partition or rearrange array in-place