dsa5 min read
Binary Search — Complete Guide: All Patterns & Problem Index
Master every binary search pattern: classic, left/right boundary, rotated array, BS on answer, and 2D matrix — with templates and full index of 45 problems.
Read →
1575 articles
Master every binary search pattern: classic, left/right boundary, rotated array, BS on answer, and 2D matrix — with templates and full index of 45 problems.
Implement classic binary search to find a target in a sorted array in O(log n) time.
Find the first bad version using left-boundary binary search: shrink hi to mid when version is bad.
Find where a target would be inserted in a sorted array using left-boundary binary search returning lo.
Compute integer square root using right-boundary binary search to find the largest k where k*k <= x.