WorkspaceLearning path
Level 1 · Foundations
BUILD YOUR INTUITION

Two Pointers

Maintain two positions whose movement preserves a useful relationship: mirrored characters, a compacted prefix, or a sorted pair sum.

THE MENTAL MODEL

When should this come to mind?

Maintain two positions whose movement preserves a useful relationship: mirrored characters, a compacted prefix, or a sorted pair sum.

Compare opposite endsStable in-place compactionSorted pair search

What makes it work

Specify which indices have already been processed and whether the pointers may meet or cross.

When to choose something else

Without a reason to discard positions permanently, moving a pointer may skip valid answers.

See the pattern in action

Change the input. Follow the state. Make it yours.