Skip to content
C Codeloom

Topics / Two Pointers

↔️

Two Pointers

Two indices walking an array — the technique behind 3Sum, palindrome checks, and container problems.

Why learn Two Pointers?

  • Converts many O(n²) brute forces into O(n) one-pass solutions.

  • A single pattern that unlocks 30+ classic problems.

  • Appears constantly in mid-level interviews.

What you can build with Two Pointers

Sorted-array pair / triple problems Palindrome and substring checks In-place array modification (remove duplicates, move zeros)

Two Pointers tutorials

4 articles

Hand-written tutorials, ordered as a recommended learning path.

  1. 01 Two Pointers A practical guide to the two pointers technique — opposite-end and same-direction patterns, when to use each, and six classic interview problems with worked solutions.
  2. 02 3Sum A careful walkthrough of LeetCode 15 3Sum using sort plus two pointers. We handle duplicate triplets cleanly and avoid the classic off-by-one traps.
  3. 03 Container Water Solve LeetCode 11 Container With Most Water with the two-pointer technique. We prove correctness and contrast it with the quadratic brute force.
  4. 04 Trapping Rain Water Solve LeetCode 42 Trapping Rain Water in linear time and constant space using the two-pointer technique. Brute force, optimal walkthrough, and interview talk track.