Workspace

Binary Search

3 day streakD
All algorithms

Binary search algorithms.

Find boundaries, uncover structure, and search the answer space.

20 lessons · Python & C++

Search & boundaries

ProblemDifficultyTime complexityPractice
Binary SearchEasyO(log n)LeetCode
Lower Bound & Search Insert PositionEasyO(log n)—
Upper BoundEasyO(log n)—
First & Last OccurrenceMediumO(log n)—

Rotations & structure

ProblemDifficultyTime complexityPractice
Search in a Rotated Sorted ArrayMediumO(log n)—
Rotated Search with DuplicatesMediumO(n) worst case—
Minimum in a Rotated Sorted ArrayMediumO(log n)—
Find a Peak ElementMediumO(log n)—
Single Element in a Sorted ArrayMediumO(log n)—

Numbers & matrices

ProblemDifficultyTime complexityPractice
Integer Square RootEasyO(log x)—
Exact Integer Nth RootMediumO(p log x)—
Search a 2D MatrixMediumO(log(rc))—
Kth Smallest in a Sorted MatrixMediumO((r + c) log W)—

Search on the answer

ProblemDifficultyTime complexityPractice
Koko Eating BananasMediumO(n log M)—
Capacity to Ship Packages Within D DaysMediumO(n log S)—
Split Array Largest SumHardO(n log S)—
Minimum Days to Make BouquetsMediumO(n log M)—
Aggressive Cows / Maximum Minimum DistanceMediumO(n log n + n log W)—

Two-array partitions

ProblemDifficultyTime complexityPractice
Median of Two Sorted ArraysHardO(log(min(n, m) + 1))—
Kth Element of Two Sorted ArraysHardO(log(min(n, m) + 1))—

A good place to start

Explore a pattern

A little guidance

Start with a pattern, read through a problem, and mark it solved when the idea clicks. Save anything you want to revisit.

New tutorials are added one at a time. Your bookmarks and solved checkmarks stay in this browser.

Explore the roadmap