Binary Search

Every comparison throws away half of what's left. Twenty questions beats a million.

5 lessons · ~49 min · free

By the end you can

  1. The power of throwing half away8 minThe guessing game, log₂ growth, and what sorted order actually buys you.
  2. The classic template11 minlo, hi, mid, and the loop condition, plus the two bugs that cause infinite loops.
  3. Boundaries: first and last11 minFirst occurrence, last occurrence, and the first-true picture that unifies them.
  4. Searching the answer space11 minNo array, no problem: binary search over candidate answers with a yes/no check.
  5. Spotting binary search problems8 minMonotonic structure in disguise, rotated arrays, and when halving simply doesn't apply.

The account is free and so is every lesson. It unlocks the courses and saves your progress.

Practice it after

The final lesson links here too: real interview questions that test this pattern, in an editor with execution and AI feedback.