Skip to content
CodeItRaw
Path

Splitting a problem into smaller copies of itself: base cases, backtracking and merge sort.

Key ideas

  • Base case first: what is the answer for the smallest input?
  • Reduce the problem to a smaller copy of itself and trust that answer.
  • Divide and conquer: split in two, solve both halves, merge (like merge sort).

Pattern

def go(lo, hi):
    if hi - lo <= 1:
        return base_answer(lo)
    mid = (lo + hi) // 2
    return combine(go(lo, mid), go(mid, hi))

Finish these first:Arrays

Lessons

Each lesson explains one idea from zero and ends with a few tasks. Lessons open in order; the explanation can be read at any time.

  1. 01

    A function that calls itself

    0/2 tasks

  2. 02

    Ways to make the problem smaller

    0/2 tasks

  3. 03

    Branching calls: take it or leave it

    0/3 tasks

Boss

  • 04

    Inversions

    Function

  • The boss opens when every lesson of the topic is finished. Solve it too and the topic is complete, and the topics after it open.