Section Recap

Summary of two pointer patterns.

Three patterns: opposite direction, same direction, sorted tricks.

Recognition:

  • Pairs in sorted array → Opposite pointers
  • In-place modification → Read/write
  • Cycle detection → Fast/slow
  • Merging sorted → Two forward pointers

Requirements: Monotonic property, pointer movement makes progress, can discard search space.

Reduces O(n2)O(n^2) to O(n)O(n). Building block for sliding window.