starter30 min · 2 steps
Track

Two-pointer walks, in and out

The pair-of-indices trick that solves half of the string and array interview questions.

Why this track

Two pointers marching from opposite ends, or in the same direction at different speeds, is the second-most-recycled interview pattern after hash-map lookup. Reverse in place, palindromes, sorted-array pair sums — same three-line skeleton every time.

By the end you should be able to spot the shape from the problem statement alone: "in-place", "sorted array", "reverse" — all two-pointer tells.

Progression

Follow the order

  1. 01
    problem
    Reverse String
    Reverse the input string. In-place is preferred where the language allows.
    Warm-up — the simplest instance. Swap and shrink until the pointers meet.
  2. 02
    problem
    Valid Parentheses
    Given a string containing only (){}[], determine whether every opener has its matching closer, correctly nested.
    Same intuition, different data structure. Stack the openers, pop on closers.
Get started

Ready to start?