HomeTwo Pointers
Two Pointers
Two indices sweeping an array — from both ends or at two speeds.
9 shown
- IntroductionWhy two indices beat one nested loopanimatedEasy
- Two Sum IISorted input · find indices that add up to targetanimatedMedium
- Valid PalindromeConverging pointers · skip non-alphanumericsanimatedEasy
- 3SumFind all unique triplets that sum to zeroanimatedMedium
- Container With Most WaterPick two lines that hold the most wateranimatedMedium
- Valid Triangle NumberCount triples that form a triangleanimatedMedium
- Move ZeroesIn-place · keep non-zeros in orderanimatedEasy
- Sort ColorsDutch National Flag · in-place · three pointersanimatedMedium
- Trapping Rain WaterWater held between bars of varying heightsanimatedHard