Skip to content

Binary Search

Guess a number from 1–100: ask "higher or lower?" and you need at most 7 guesses. Whenever you can answer a yes/no question that cuts the possibilities in half, you can solve in O(log n). It also works on answers, not only arrays.

After this topic: You can write a bug-free binary search, adapt it to rotated arrays, and search over the answer itself.

Do these first: Two Pointers

0 of 7 solved0%

Step 1 · Read the lesson

Binary Search

Halve the search space whenever a yes/no condition is monotonic.

Step 2 · Solve the problems in order

Try each one for about 20 minutes first. Problems with a Run code tab are checked right here. If you are stuck, open Nudge, think again, then Idea. Go skeleton only gives the function shape, and Reference solution is for comparing after you have tried. Tick the box when you could solve it again without help.

Step 3 · What this unlocks