CoursesArray Patterns

Two Pointers

Lessons
9
Exercises
56
Minutes
57
  1. 1

    When Two Pointers Apply

    Spot the problems where two converging pointers beat checking every pair.

    Multiple choiceTap
    5 exercises
    4 min
  2. 2

    Two Sum II

    Use the sorted order to decide which pointer moves — and never rescan.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    6 min
  3. 3

    Container With Most Water

    The shorter wall limits the area — so it is always the one that moves.

    Complete codeMultiple choiceTrace
    6 exercises
    6 min
  4. 4

    Move Zeroes

    Compact non-zero values in-place with reader/writer pointers, preserving their order.

    Complete codeDebugMultiple choiceTapTrace
    6 exercises
    6 min
  5. 5

    3Sum

    Sort, fix one element, and reduce the rest to a two-pointer pair search — skipping duplicates as you scan.

    Code orderMultiple choiceTrace
    6 exercises
    7 min
  6. 6

    Sort Colors

    Partition 0s, 1s, and 2s in one pass with three pointers — and learn why mid stays put after swapping with high.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    6 min
  7. 7

    Two Pointers CheckpointCheckpoint

    No new concepts — transfer the island's converging-pointer rules to a fresh problem: counting valid triangles from sorted side lengths.

    DebugCode orderFill blankMultiple choiceTrace
    6 exercises
    6 min
  8. 8

    Two Pointers ReviewReview

    Mixed recap of the island: choosing a pointer setup, the move rule, reader/writer compaction, three-way partitioning, and dedup.

    Complete codeDebugMultiple choiceTapTrace
    7 exercises
    6 min
  9. 9

    Boss: Trapping Rain WaterBoss

    The classic hard problem, tamed: water at each bar is min(maxLeft, maxRight) - height, and two pointers settle whichever side's bound is already decided.

    Complete codeDebugCode orderMultiple choiceTrace
    8 exercises
    10 min
AlgoFox Pro

Array Patterns is part of AlgoFox Pro

You can read the whole course outline here. The exercises are in the app, along with your streak, your mistake review, and the progress that carries across your devices.

Pro starts with a 3 day free trial. The app store decides who is eligible for an introductory offer, and a lapsed subscription does not get another one.

Download AlgoFox on the App StoreGet AlgoFox on Google Play

Already subscribed in the app? Sign in with the same account and Pro works here too. Quick Play and Battle are free on the web, and so is the first course in every subject.