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.
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.