</>CodexBash
Learn path · free to read

One idea at a time, then the problems that use it

A path from counting digits to graphs, numbered so you always know where you are. Each lesson explains a single technique, shows it running step by step, and hands you the problems where it is the right answer. C, C++, Java and Python are only ways of talking to a computer. The thinking is what carries across.

36 lessons, in order. Start at one, or start where you are stuck.

First steps

steps 1 to 6
  1. How a solution runs here

    Beginner8 min read

    What the judge does with your code: you write one function, it reads the input, calls you and checks what you return. The same problem in C, C++, Java and Python.

    0 of 3 practice problems solved

  2. Values, types and the numbers that overflow

    Beginner10 min read

    Whole numbers and how big they get, dividing without fractions, remainders, doubles that are almost right, and text in four languages.

    0 of 3 practice problems solved

  3. Decisions and loops

    Beginner10 min read

    if and else, for and while, stopping early, the off by one error, and why a loop inside a loop is too slow for large inputs.

    0 of 3 practice problems solved

  4. Functions, helpers and what happens to arguments

    Beginner9 min read

    Splitting a solution into small named helpers, which arguments a function can change for its caller, and returning more than one value.

    0 of 3 practice problems solved

  5. Arrays and lists in everyday code

    Beginner10 min read

    Fixed and growable arrays, returning one to the judge, sorting with the built-in sort, and building grids without the classic Python trap.

    0 of 3 practice problems solved

  6. Maps and sets in everyday code

    Beginner9 min read

    Finding things by value rather than position: sets, maps and counting in C++, Java and Python, and the array tricks that stand in for them in C.

    0 of 3 practice problems solved

Numbers

step 7
  1. Numbers: the digits inside them

    Beginner9 min read

    Two operations, remainder and division, take any number apart digit by digit. Almost every beginner number problem is that one loop with a different thing done to each digit.

    0 of 4 practice problems solved

Arrays and hashing

steps 8 to 12
  1. Where your data actually lives

    Beginner8 min read

    Memory is one long numbered street. Almost every cost in this course comes from that one fact, so it is worth ten minutes before anything else.

    0 of 4 practice problems solved

  2. Arrays: what is cheap and what is not

    Beginner9 min read

    Four operations, four different costs. Knowing which is which turns most array problems from guesswork into arithmetic.

    0 of 10 practice problems solved

  3. Hash tables: how a lookup can skip the search

    Beginner11 min read

    Turn a key into a number, use that number as an address. The whole trick, plus what happens when two keys collide.

    0 of 4 practice problems solved

  4. Trading memory for time with a hash map

    Beginner12 min read

    Why a second pass beats a nested loop, and how remembering what you have seen turns a quadratic search into a single sweep.

    0 of 12 practice problems solved

  5. Carrying an answer forward: Kadane's algorithm

    Intermediate12 min read

    The best subarray ending here is either this element alone or this element added to the best one ending just before it. That single sentence is the algorithm.

    0 of 5 practice problems solved

Two pointers and windows

steps 13 to 14
  1. Two pointers: replacing a nested loop with a single pass

    Beginner10 min read

    Two indexes walking one array, never going backwards. Turns a great many quadratic solutions into linear ones.

    0 of 13 practice problems solved

  2. Sliding windows: fixed size, then variable

    Intermediate14 min read

    A window is a stretch of a list you keep looking at while both its ends move right. Get the fixed-size version first, because the variable one is the same idea with a rule instead of a length.

    0 of 8 practice problems solved

Recursion

step 15
  1. Recursion: trusting the smaller problem

    Beginner12 min read

    A function that calls itself is not magic and not a loop in disguise. It is a machine that takes one step and hands the rest to a copy of itself, with the call stack keeping the paperwork.

    0 of 8 practice problems solved

Sorting

step 16
  1. Sorting: which one, and why you will not write any of them

    Beginner14 min read

    You will call the library sort. The reason to know the algorithms anyway is that their ideas turn up inside problems that are not about sorting at all.

    0 of 5 practice problems solved

Searching

steps 17 to 18
  1. Binary search, and getting the boundary right

    Beginner14 min read

    Halving the search space is the easy part. The hard part is deciding what to return when the value is not there.

    0 of 7 practice problems solved

  2. Binary search on the answer, when nothing is sorted

    Intermediate13 min read

    A dozen questions that look nothing alike are one question: guess an answer, check it in a single pass, and use the fact that answers come in a run of no followed by a run of yes.

    0 of 4 practice problems solved

Linked lists

steps 19 to 20
  1. Linked lists: giving up indexing to buy insertion

    Beginner10 min read

    Values that do not sit next to each other, each one holding the address of the next. The exact opposite trade from an array.

    0 of 5 practice problems solved

  2. Loops in a linked list: two walkers, no extra memory

    Intermediate13 min read

    A list that points back at itself has no end to find. One slow walker and one fast one settle whether there is a loop, how long it is, where it starts and how to cut it, using two variables and nothing else.

    0 of 5 practice problems solved

Stacks and queues

steps 21 to 23
  1. Stacks and queues: choosing which end to work from

    Beginner9 min read

    Two structures that differ by one decision: when you take something out, is it the newest or the oldest?

    0 of 11 practice problems solved

  2. Stacks: when the most recent thing is the thing that matters

    Beginner10 min read

    Nesting is the signal. When the correct partner for what you are looking at is always the most recent unmatched item, you want a stack.

    0 of 3 practice problems solved

  3. Monotonic stacks: the nearest bigger thing, in one pass

    Intermediate12 min read

    A whole family of problems asks for the nearest larger or smaller value. They all fall to a stack kept in sorted order, and they all cost one pass.

    0 of 5 practice problems solved

Trees

steps 24 to 26
  1. Trees: one thing above, several below

    Beginner10 min read

    A linked list that branches. Everything about trees comes from that, including why searching a balanced one is so fast.

    0 of 8 practice problems solved

  2. Traversals: four orders, and which question each answers

    Beginner12 min read

    Preorder, inorder and postorder differ by one line's position. Level order differs by using a queue instead of recursion, and that single change is the whole idea behind breadth-first search.

    0 of 5 practice problems solved

  3. Search trees: one rule, and everything that follows from it

    Intermediate13 min read

    A search tree keeps smaller on the left and larger on the right. Every operation on one, and every trap, comes from taking that rule seriously across the whole tree rather than one node at a time.

    0 of 3 practice problems solved

Heaps

steps 27 to 28
  1. Heaps: when you only ever want the next one

    Intermediate10 min read

    A tree that gives up on full sorting and keeps only one promise: the smallest is on top. That is cheaper, and often it is all you need.

    0 of 4 practice problems solved

  2. Two heaps: keeping the middle in view

    Advanced16 min read

    A heap gives you the extreme of a set in constant time. Point two of them at each other and the extreme becomes the median.

    0 of 3 practice problems solved

Graphs

steps 29 to 31
  1. Graphs: things, and the connections between them

    Intermediate11 min read

    Drop the rule that every node has one parent and you have a graph. Two ways to walk one, and the choice decides what you can prove.

    0 of 4 practice problems solved

  2. Breadth first and depth first: the same loop, a different container

    Intermediate13 min read

    Both walks visit everything reachable. Only one of them answers questions about shortest, and the difference between them is which end you take things off.

    0 of 4 practice problems solved

  3. Topological order: doing things in an order that works

    Intermediate16 min read

    Courses with prerequisites, build steps, task lists. If the dependencies contain a cycle there is no valid order, and finding that out is the same algorithm.

    0 of 3 practice problems solved

Backtracking

steps 32 to 33
  1. Backtracking: choose, explore, un-choose

    Intermediate15 min read

    When a problem asks for every arrangement rather than one number, you need a way to try each choice and take it back. Three lines do it, and one of them is the line everybody forgets.

    0 of 6 practice problems solved

  2. Tries and backtracking: searching many words at once

    Advanced18 min read

    Searching a grid for one word is backtracking. Searching for a thousand is backtracking with the dictionary turned inside out.

    0 of 3 practice problems solved

Dynamic programming

steps 34 to 35
  1. Dynamic programming without the mystique

    Advanced20 min read

    A state, a recurrence, and an order to fill it in. Longest increasing subsequence, first the honest way and then the fast one.

    0 of 6 practice problems solved

  2. Grid DP: when the table is the same shape as the problem

    Intermediate12 min read

    A grid you can only cross one way is where dynamic programming is easiest to see, because the table of answers has the same shape as the board and you can watch it fill.

    0 of 3 practice problems solved

Greedy

step 36
  1. Greedy: when the obvious move is the right one

    Intermediate11 min read

    Taking the best step available right now is usually wrong. The interesting part is the small number of problems where it is provably right, and how to tell.

    0 of 4 practice problems solved