Search a target in a rotated sorted array with no duplicates. Modified binary search identifies which half is sorted, then checks the target range. O(log n) time.
March 19, 2026 Read →
Find the minimum element in a rotated sorted array with no duplicates. Binary search: the minimum is in the unsorted half. O(log n) time O(1) space.
March 19, 2026 Read →
Find the one duplicate in [1..n] without modifying the array using Floyd's tortoise-and-hare cycle detection.
March 19, 2026 Read →
Find a peak element in O(log n) by binary searching on the slope direction — always move toward the higher neighbor.
March 19, 2026 Read →
Find the median of two sorted arrays in O(log(min(m,n))) by binary searching for the correct partition point.
March 19, 2026 Read →
Minimize the largest sum among m subarrays by binary searching on the answer and greedy checking feasibility.
March 19, 2026 Read →
Find the longest substring that appears at least twice using binary search on length and Rabin-Karp rolling hash for O(n log n) average time.
March 19, 2026 Read →
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.
March 19, 2026 Read →
Implement classic binary search to find a target in a sorted array in O(log n) time.
March 19, 2026 Read →
Find the first bad version using left-boundary binary search: shrink hi to mid when version is bad.
March 19, 2026 Read →
Find where a target would be inserted in a sorted array using left-boundary binary search returning lo.
March 19, 2026 Read →
Compute integer square root using right-boundary binary search to find the largest k where k*k <= x.
March 19, 2026 Read →
Find the starting and ending positions of a target in a sorted array using two separate binary searches.
March 19, 2026 Read →
Search in a rotated sorted array by identifying which half is sorted and narrowing accordingly.
March 19, 2026 Read →
Find the minimum element in a rotated sorted array by comparing mid with right boundary to locate the rotation point.
March 19, 2026 Read →
Search a row-column sorted 2D matrix in O(log(m*n)) by treating it as a virtual 1D sorted array.
March 19, 2026 Read →
Find the minimum eating speed for Koko to finish all bananas in h hours using binary search on the answer space.
March 19, 2026 Read →
Find the minimum ship capacity to ship all packages within d days using binary search on capacity.
March 19, 2026 Read →
Find any peak element in O(log n) by always moving toward the uphill neighbor, which guarantees finding a peak.
March 19, 2026 Read →
Find the k closest elements to x in a sorted array by binary searching for the optimal left window boundary.
March 19, 2026 Read →
Find the single non-duplicate element in O(log n) by observing that pairs shift the parity of indices after the singleton.
March 19, 2026 Read →
Find the length of LIS in O(n log n) using patience sorting: binary search to maintain a sorted tails array.
March 19, 2026 Read →
Minimize the largest subarray sum when splitting into k parts using binary search on the possible answer range.
March 19, 2026 Read →
Search in a rotated sorted array that may contain duplicates by skipping lo++ when mid equals both boundaries.
March 19, 2026 Read →
Find the minimum day to make m bouquets of k adjacent flowers using binary search on the day value.
March 19, 2026 Read →
Find h-index from a sorted citations array in O(log n) using left-boundary binary search.
March 19, 2026 Read →
Count spell-potion pairs with product >= success by sorting potions and binary searching for each spell's threshold.
March 19, 2026 Read →
Find the kth smallest element in a row-column sorted matrix by binary searching on the value range.
March 19, 2026 Read →
Maximize the minimum distance between m balls in baskets using binary search on the answer (minimum distance).
March 19, 2026 Read →
Find the minimum in a rotated array with duplicates by shrinking hi-- when nums[mid]==nums[hi].
March 19, 2026 Read →
Find the median of two sorted arrays in O(log(min(m,n))) by binary searching for the correct partition point.
March 19, 2026 Read →
Count smaller elements to the right of each element using merge sort with position tracking in O(n log n).
March 19, 2026 Read →
Find the maximum number of nested envelopes by sorting by width ascending then height descending, then applying LIS.
March 19, 2026 Read →
Minimize the maximum value after performing k operations (average adjacent elements) using binary search on the answer.
March 19, 2026 Read →
Find the maximum length to cut k ribbons from given ribbons using binary search on the ribbon length.
March 19, 2026 Read →
Maximize nums[index] given array length n, sum constraint maxSum, and each element >= 1 using binary search on the peak value.
March 19, 2026 Read →
Find the kth missing number in a sorted array by binary searching on the number of missing elements up to each index.
March 19, 2026 Read →
Search a row-column sorted 2D matrix in O(m+n) using the staircase technique from top-right corner.
March 19, 2026 Read →
Place c cows in stalls to maximize the minimum distance between any two cows using binary search on the answer.
March 19, 2026 Read →
Count subarrays with sum in [lower, upper] using merge sort on prefix sums for O(n log n) complexity.
March 19, 2026 Read →
Find the picked number using binary search with the guess() API that returns -1, 0, or 1.
March 19, 2026 Read →
Count negatives in a sorted matrix in O(m+n) using the staircase approach or O(m log n) with binary search per row.
March 19, 2026 Read →
Check if a number is a perfect square in O(log n) using binary search or by exploiting odd-number sum identity.
March 19, 2026 Read →
Find the smallest letter in a circular sorted list that is greater than the target using left-boundary binary search.
March 19, 2026 Read →
Answer election queries for who is leading at time t by precomputing the leader at each vote and binary searching.
March 19, 2026 Read →
Find the duplicate in array of n+1 integers in [1,n] using binary search on value with count-of-smaller logic.
March 19, 2026 Read →
Find the kth smallest prime fraction from an array using binary search on the fraction value with a counting function.
March 19, 2026 Read →
Check if any element and its double both exist in an array using a hash set or sorting with binary search.
March 19, 2026 Read →
Implement get(key, timestamp) using binary search on stored sorted timestamps for O(log n) retrieval.
March 19, 2026 Read →
Maximize events attended by greedily attending the event with the earliest end date each day using binary search.
March 19, 2026 Read →
Find the kth smallest element from two sorted arrays in O(log(m+n)) using binary elimination of k/2 elements per step.
March 19, 2026 Read →
Find the minimum train speed to arrive on time given n rides (last ride doesn't wait) using binary search on speed.
March 19, 2026 Read →
Complete cheatsheet for Binary Search: all 7 patterns, the universal template, BS on answer guide, Big O reference, and MAANG priority.
March 19, 2026 Read →
Find path from top-left to bottom-right minimizing maximum absolute difference between consecutive cells. Use Dijkstra or binary search + BFS.
March 19, 2026 Read →
Implement weighted random selection by building a prefix sum array and using binary search to find the sampled index.
March 19, 2026 Read →
Design a time-stamped key-value store supporting set and get(key, timestamp) using binary search on sorted timestamps.
March 19, 2026 Read →
Find K closest elements to x in a sorted array using binary search to find the optimal left boundary.
March 19, 2026 Read →
Find the Kth smallest element in an n×n row-and-column sorted matrix using binary search on value range or heap.
March 19, 2026 Read →
Find minimum time to swim from top-left to bottom-right in a grid where time = max elevation on the path.
March 19, 2026 Read →
Find the nth number divisible by a, b, or c using binary search with inclusion-exclusion counting formula.
March 19, 2026 Read →
For each interval find the interval with the smallest start point >= the end point using sorted starts and binary search.
March 19, 2026 Read →
Count nodes in a complete binary tree in O(log^2 n) by comparing left and right heights to identify full subtrees.
March 19, 2026 Read →
Count nodes in complete binary tree in O(log^2 n) by comparing left vs right subtree heights recursively.
March 19, 2026 Read →
Find two numbers summing to target in a 1-indexed sorted array using inward two pointers in O(n) time O(1) space.
March 19, 2026 Read →
Find k closest integers to x in a sorted array using binary search to locate the optimal left boundary of the window.
March 19, 2026 Read →
Find the path from source to destination minimising the maximum edge weight. Binary search on the answer + BFS/DFS connectivity check. O(E log W) total.
March 1, 2025 Read →
Find the minimum time to swim from (0,0) to (n-1,n-1) where you can only move to a cell when time >= cell value. Two approaches: Dijkstra O(n² log n) and binary search + BFS O(n² log n).
March 1, 2025 Read →
Search for a target in a matrix where each row and column is sorted. O(m+n) solution using top-right corner elimination — a classic Google interview problem.
February 15, 2025 Read →
Find the median of two sorted arrays in O(log(min(m,n))) time using binary search on partition points. A classic hard problem testing deep binary search understanding.
February 15, 2025 Read →
Design a key-value store that returns values at or before a given timestamp. Uses a hashmap of sorted (timestamp, value) lists with binary search for O(log n) get.
February 10, 2025 Read →