Binary Search — Classic Exact Target
Implement classic binary search to find a target in a sorted array in O(log n) time.
webcoderspeed.com
10 articles
Implement classic binary search to find a target in a sorted array in O(log n) time.
Search in a rotated sorted array by identifying which half is sorted and narrowing accordingly.
Find the length of LIS in O(n log n) using patience sorting: binary search to maintain a sorted tails array.
Find the median of two sorted arrays in O(log(min(m,n))) by binary searching for the correct partition point.
Place c cows in stalls to maximize the minimum distance between any two cows using binary search on the answer.
Find the picked number using binary search with the guess() API that returns -1, 0, or 1.
Check if a number is a perfect square in O(log n) using binary search or by exploiting odd-number sum identity.
Find the duplicate in array of n+1 integers in [1,n] using binary search on value with count-of-smaller logic.
Check if any element and its double both exist in an array using a hash set or sorting with binary search.
Calculate trapped rainwater volume using a monotonic stack that computes water in horizontal layers as bars are processed.