Engineer Atlas
OverviewLearnVisualizerAlgorithm FinderPatternsComplexityRoadmapPracticeInterview
OverviewLearnVisualizerAlgorithm FinderPatternsComplexityRoadmapPracticeInterviewCheat SheetCompare
Data Structures
  • Fundamentals
  • Stack & Queue
  • Hashing
  • Trees
  • Heaps
  • Graphs
  • Specialized Structures
Algorithms
  • Searching
  • Sorting
  • Two Pointers
  • Sliding Window
  • Prefix Techniques
  • Recursion & Backtracking
  • Divide & Conquer
  • Greedy
  • Dynamic Programming
  • Graph Algorithms
  • String Algorithms
  • Bit Manipulation
  • Mathematical Algorithms
Learn/Algorithms/Two Pointers
Two Pointers

Two Pointers

Opposite-direction, same-direction, fast & slow pointers and partitioning.

Two Pointers (Opposite Ends)
▶ viz

Walk one pointer in from each end of a sorted (or monotone-bounded) array, moving whichever side cannot improve the answer.

O(n) · O(1) space
Two Pointers (Same Direction)
▶ viz

A read pointer scans every element while a write pointer marks the end of the finished prefix, compacting or filtering an array in place in one pass.

O(n) · O(1) space
Fast & Slow Pointers
▶ viz

Advance one pointer twice as fast as another through a linked structure to find cycles, cycle starts, midpoints, and k-th-from-end nodes in O(1) space.

O(n) · O(1) space
Partitioning
▶ viz

Rearrange an array in place so that elements less than, equal to, and greater than a pivot occupy contiguous regions, using pointers that mark region boundaries.

O(n) · O(1) space
Engineer Atlas
GitHub·LinkedIn