Binary Search
Cut a sorted range in half on every step to find a value or boundary in O(log n) instead of checking one by one.
Binary Search Practice Problems
Easy
4 problems- 21easy
Binary Search
Find the index of a target value in a sorted array.
- 22easy
Search Insert Position
Find the index where a target value is, or where it should be inserted, in a sorted array.
- 23easy
First Bad Version
Find the first bad version in a sequence using as few checks as possible.
- 24easy
Sqrt(x)
Compute the integer square root of a number without using built-in power functions.
Medium
5 problems- 25medium
Search in Rotated Sorted Array
Find a target value in a sorted array that has been rotated at an unknown point.
- 26medium
Find First and Last Position of Element in Sorted Array
Find the first and last index of a target value in a sorted array.
- 27medium
Find Peak Element
Find any element in an array that is bigger than both of its neighbors.
- 28medium
Search a 2D Matrix
Find a target value inside a matrix where each row and column is sorted.
- 29medium
Koko Eating Bananas
Find the slowest eating speed that still finishes every pile of bananas in time.
Hard
2 problemsRelated concepts
| Topic | Description |
|---|---|
| Sliding Window | Solve fixed-window problems: maximum sum of k elements, moving averages, and O(n) updates as the window slides. |
| Two Pointers | Scan a sorted array or string from both ends at once to find pairs, remove duplicates, or reverse data in O(n). |
| Depth-First Search | Explore as far as possible down one path before backtracking, used to walk trees, graphs, and grids. |
| Breadth-First Search | Explore level by level from a starting point, the go-to way to find the shortest path in an unweighted graph. |
| Dynamic Programming | Break a problem into overlapping subproblems and reuse their answers to avoid recomputing the same work. |
| Backtracking | Try a choice, keep going, and undo it if it fails, used to generate permutations, combinations, and valid layouts. |