When it applies
Sorted arrays, palindromes, partitioning, and problems where moving one pointer dominates the other based on a comparison.
Lesson
Move two indices cooperatively to shrink search space in linear time.
Loading solution…
Sorted arrays, palindromes, partitioning, and problems where moving one pointer dominates the other based on a comparison.
Open the Two Pointers studio lesson. Watch L and R converge while the code line highlight tracks the branch you take on each sum comparison.
After sorting, if A[L]+A[R] is too small, any pair using L with a smaller R is worse — so advance L. Symmetric argument for R.
Showing 24 of the related problems in the 1000-question bank.
Container With Most Water
Two Pointers
3Sum
Two Pointers
3Sum Closest
Two Pointers
4Sum
Two Pointers
Remove Nth Node From End of List
Linked List
Remove Duplicates from Sorted Array
Two Pointers
Remove Element
Two Pointers
Find the Index of the First Occurrence in a String
String
Next Permutation
Two Pointers
Trapping Rain Water
Two Pointers
Rotate List
Linked List
Sort Colors
Two Pointers
Merge Sorted Array
Two Pointers
Valid Palindrome
Two Pointers
Linked List Cycle
Two Pointers
Linked List Cycle II
Two Pointers
Reorder List
Linked List
Sort List
Merge Sort
Intersection of Two Linked Lists
Two Pointers
Two Sum II - Input Array Is Sorted
Two Pointers
Palindrome Linked List
Linked List
Find the Duplicate Number
Floyd
Intersection of Two Arrays II
Hash Map
Partition Labels
Greedy
Got the lesson?
Mark Two Pointers as understood when the ideas stick.