Skip to content
Algorithms for Beginners

Learn algorithms step by step, with a code editor in your browser

An algorithm is just a set of steps for solving a problem. Coding interview questions look endless, but they are built from a small set of repeating ideas, which we call patterns. Learn the ideas, and you can solve problems you have never seen. No experience needed, and everything is free.

See each pattern move

Every pattern and every problem comes with animations like this one. Press Guess each step first to predict what happens before you see it.

Watch it work: close in from both ends

sorted

target =
16
sum =
–

The list is sorted. Put left on the smallest number and right on the biggest. We want two that add up to 16.

Learn two pointers step by step

How it works

  1. Step 1

    Learn the basics

    Never written code? Start here. Short lessons cover variables, arrays, loops and functions, with examples you can run.

  2. Step 2

    Learn the patterns

    Most coding problems are one of about twenty patterns (reusable tricks) in disguise. Each pattern is explained step by step, with animations.

  3. Step 3

    Break the problem down

    Before any code, answer the questions a good problem-solver asks: what goes in, what comes out, what's the slow way, and which pattern fits.

  4. Step 4

    Practise in your browser

    Write JavaScript in the editor, press Run, and see which tests pass. Hints unlock one at a time when you are stuck.

  5. Step 5

    Make it stick

    Rebuild each template and solution from memory in four steps, then review it on a schedule that brings it back just before you'd forget.

The first five patterns

  • Hashing and counting

    Remember what you have seen in a Map, so you never search for it twice.

  • Two pointers

    Walk through a list from both ends (or at two speeds) at once.

  • Sliding window

    Keep a stretch of the list and slide it along instead of starting over.

  • Binary search

    Halve the search space with every guess.

  • Stack

    Keep the most recent unfinished thing on top, and finish it first.

See all 19 patterns