Learn / macOS

Learn an algorithm pattern and apply it

Trace a technique, explain why it works, and apply it to a coding challenge.

Algorithms with the ordered lesson catalog and a worked lesson.
Algorithms with the ordered lesson catalog and a worked lesson. Select the image to enlarge.
  1. Recognize the technique

    Read the recognition cues and a worked example. Write the input conditions that make the technique useful.

    Example

    Two pointers can find a pair in a sorted array. Explain what would break if the input were unsorted.

  2. Predict the next visual step

    Open the visualization and step through it. Before advancing, predict which pointer, node, or state will change and why.

    Example

    For [1, 2, 4, 6] and target 8, start with 1 + 6. Because 7 is too small, move the left pointer. Now 2 + 6 equals 8.

  3. Complete a drill and transfer it

    Answer a lesson drill, then use Practice This Technique where offered. Write the invariant before implementing the related challenge.

    Example

    Explain why moving the left pointer discards no valid pair when the sum is too small. Apply that reasoning on a different sorted array.

Check your work

You can predict a step before the visualization shows it and solve a related input by explaining the same invariant.

Try it yourself

Open an array pattern lesson and trace a case with duplicates. For a sorted pair search on [1, 2, 2, 5] with target 4, predict both pointer moves before pressing next.

What to look for
Start at 1 + 5, move the right pointer because the sum is too high, then move the left pointer when 1 + 2 is too low. The two occurrences of 2 are at distinct indices.