Level 2 · Core
Free Binary search lessons
12 lessons, about 134 minutes in all. Each teaches one idea with a visual, then gives you one problem built for it. Read the lessons here, then create a free account to solve the problems and keep your progress.
Stage 0Halving the search
- Find it by halvingLook in the middle, then throw away the half that can't hold the answer.9 min
- Where would it go?Find the first spot where a value would fit, even if it isn't there.10 min
- Count the copiesTwo searches find where a value's run starts and ends.9 min
- Search the answersNo list at all. Halve the range of possible answers instead.10 min
Stage 1First and last position
- Find the first oneWhen you find a match, don't stop — keep searching left for an earlier one.8 min
- Find the last oneThe mirror image of the last step — remember the match, then keep searching right.8 min
- The range of a valueCombine both searches into one answer, with one check for "not found."9 min
- Beyond equalityThe same "remember it, then narrow" idea, aimed at a question that isn't about equality at all.10 min
Stage 2Search on the answer
- Guess the answer, then check itFind the smallest speed that finishes the job in time, by halving the range of possible speeds.15 min
- The smallest truck that will doFind the smallest capacity that ships all the packages in order within a number of days.15 min
- As far apart as possibleFind the largest minimum gap you can keep when placing items, by searching gaps and checking them greedily.15 min
- The k-th smallest gapFind the k-th smallest difference between pairs without listing the pairs, by searching the difference and counting pairs under it.16 min
There’s more after this
These are the opening stages of Binary search. The full path climbs on to harder problems and a mastery test. Create a free account and we’ll keep your place.
Start the full path free