Back to writing

Two pointers: when to think in terms of narrowing from both ends

Two pointers are useful when moving one boundary can eliminate a large set of impossible combinations.

Two pointers are useful when moving one boundary can eliminate a large set of impossible combinations.

Typical signals:

  • sorted data
  • two-position relationships
  • brute force would be quadratic