O(log N), O(sort)
The pure logarithmic-time family: classic search, the bisect boundary toolkit, and the dozens of variants that are really just one of those templates with a twist. When the input isn't sorted, an O(N log N) sort first still keeps us in this bucket.
The Classic Binary Search Algorithm
The single lower-bound template that solves almost everything else on this page.
704. Binary Search
702. Search in a Sorted Array of Unknown Size
74. Search a 2D Matrix
Bisect Algorithms
Four reusable insert-position primitives. Everything in the next sections calls one of these.
Bisect Left
Bisect Left Reverse
Bisect Right
Bisect Right Reverse
Bisect Derivatives
One bisect call, lightly post-processed.
744. Find Smallest Letter Greater Than Target
35. Search Insert Position
362. Design Hit Counter
Bisect Left & Right
Call both boundaries and work with the [left, right) span between them.
34. Find First and Last Position of Element in Sorted Array
2089. Find Target Indices After Sorting Array
1150. Check If a Number Is Majority Element in a Sorted Array
Element Occurrence
Slight Variants
The classic template with the comparison swapped for a derived predicate.
1064. Fixed Point
374. Guess Number Higher or Lower
278. First Bad Version
441. Arranging Coins
287. Find the Duplicate Number
Single Element in a Sorted Array
Math - Square
Binary search over a numeric answer range to invert a monotone math function.
69. Sqrt(x)
367. Valid Perfect Square
633. Sum of Square Numbers
Missing Elements
Bisect on a "how many are missing so far" predicate.
268. Missing Number
1060. Missing Element in Sorted Array
1539. Kth Missing Positive Number
Rotated Sorted Array
Locate the pivot (minimum), then search the right half.
Find the Pivot (Minimum)
154. Find Minimum in Rotated Sorted Array II
153. Find Minimum in Rotated Sorted Array
33. Search in Rotated Sorted Array
Peaks in an Array
Walk uphill: compare the midpoint to its neighbor and move toward the larger side.
162. Find Peak Element
852. Peak Index in a Mountain Array
1095. Find in Mountain Array
H-Index
Find the crossover point where citations meet the rank-from-the-end count.