
Find First and Last Position of Element in Sorted Array
A standard binary search finds a match. This problem asks for the entire matching block. The difference is one boundary decision.
View solutionUse binary search for ordered lookup, boundaries, rotated arrays, peaks, and monotonic partitions.
Problems
Practice problems that share this primary solution pattern and compare the clues that reveal it.

A standard binary search finds a match. This problem asks for the entire matching block. The difference is one boundary decision.
View solution
Rotation breaks global order, not all order. Find the sorted half, test its value range, and discard what that range proves impossible.
View solution
This problem asks for more. If the target is absent, return the index where it could be inserted while keeping the array sorted.
View solution
Merging is the obvious solution. It is also disqualified by the runtime requirement. The useful reframe is to search for a cut, not for a value: place…
View solution
A matrix can be two-dimensional storage with a one-dimensional search space. Prove that shape first, then run ordinary binary search over virtual indices.
View solution
Duplicates turn a clean binary-search decision into an information problem. When nums[left], nums[mid], and nums[right] are equal, you cannot tell which…
View solution