When to Use

Pattern triggers

Look for these signals in the problem:

  • "Find a pair that sums to X": Two pointers from opposite ends eliminate nested loops.
  • "Sorted array" in the problem: Sorted input lets you decide which pointer to move based on comparisons.
  • "In-place" modification required: Track read and write positions separately without extra space.
  • "Palindrome" or "reverse" keywords: Compare from both ends simultaneously.
  • "Container" or "area" problems: Move the smaller boundary inward to explore all candidates.