Two pointers [mp]
Micro pattern¶
Description¶
Coordinate moving positions so each move eliminates work or preserves a structural invariant.
Problems¶
Opposite ends¶
Move inward from both ends using comparisons or boundary guarantees.
- 125. Valid Palindrome (Top Easy)
- 344. Reverse String (Top Easy)
- 15. 3Sum (Top Medium)
- 11. Container With Most Water (Top Hard)
- 42. Trapping Rain Water (Top Hard)
Read and write pointers¶
Use one position for input and another for the next retained output.
- 26. Remove Duplicates from Sorted Array (Top Easy)
- 283. Move Zeroes (Top Easy)
Backward merge pointers¶
Read two sorted suffixes while writing the larger value into a destination suffix.
- 88. Merge Sorted Array (Top Easy)
Sliding-window boundaries¶
Advance the right boundary and move the left boundary to maintain validity.
- 3. Longest Substring Without Repeating Characters (Top Medium)
- 904. Fruit Into Baskets (Google Prep)
- 76. Minimum Window Substring (Top Hard)
Slow and fast pointers¶
Advance at different speeds or maintain a fixed gap.
- 19. Remove Nth Node From End of List (Top Easy)
- 141. Linked List Cycle (Top Easy)
- 234. Palindrome Linked List (Top Easy)
- Top-down merge sort linked list (DSA)
- 287. Find the Duplicate Number (Top Hard)
Equalize path lengths by switching heads¶
Make each pointer traverse both lists to equalize total path lengths.
- 160. Intersection of Two Linked Lists (Top Medium)
Multiple linked-list chains¶
Maintain separate tails for independently rearranged portions.
- 206. Reverse Linked List (Top Easy)
- 328. Odd Even Linked List (Top Medium)
Three-way partition pointers¶
Maintain boundaries for lower, active, and upper categories.
- 75. Sort Colors (Top Medium)
- Quick sort (DSA)
Matrix staircase pointer¶
Move across an ordered matrix while discarding rows or columns.
- 240. Search a 2D Matrix II (Top Medium)
- 378. Kth Smallest Element in a Sorted Matrix (Top Hard)
Text and pattern pointers¶
Advance text and pattern positions with a saved fallback point.
- 44. Wildcard Matching (Top Hard)