This site uses JavaScript for navigation, themes, and games like 2048. Please enable JavaScript in your browser settings, then reload the page.
23 problems. Click one to open the details.
0/23 solved
1.Binary Search on Sorted Array
Classic binary search for a target in an ascending sorted array.
2.Binary Search on Reverse Sorted Array
Search in a descending sorted array by flipping the comparison direction.
3.First and Last Occurrence
Find first and last index of a target in a sorted array with duplicates.
4.Count of an Element in Sorted Array
Count occurrences = lastIndex - firstIndex + 1.
5.How Many Times is Sorted Array Rotated
Rotation count equals index of the minimum element.
6.Find Element in Rotated Sorted Array
Search target in a rotated sorted array in O(log n).
7.Search in Nearly Sorted Array
Element may be at mid, mid-1, or mid+1 relative to sorted position.
8.Floor in a Sorted Array
Largest element ≤ target.
9.Ceil in a Sorted Array
Smallest element ≥ target.
10.Next Alphabetical Element
Ceil on characters: smallest letter strictly greater than target (circular).
11.Position in Infinite Sorted Array
Exponentially expand high bound, then binary search in the found range.
12.First 1 in Infinite Binary Sorted Array
Infinite array of 0s followed by 1s — find index of first 1.
13.Minimum Difference Element
Element in sorted array with minimum absolute difference to key.
14.Find Peak Element
Find an index where arr[i] > neighbors; binary search on slope.
15.Maximum in Bitonic Array
Bitonic array increases then decreases — max is the peak.
16.Search in Bitonic Array
Find peak, then binary search ascending left and descending right.
17.Search in Row-and-Column Wise Sorted Matrix
Start top-right (or bottom-left); eliminate a row or column each step.
18.Allocate Minimum Number of Pages
Binary search on max pages; greedy check if k students can finish.
19.Search in Rotated Sorted Array II
Rotated search with duplicates.
20.Koko Eating Bananas
Binary search min eating speed to finish in h hours.
21.Aggressive Cows
Maximize minimum distance between cows in stalls.
22.Median of Two Sorted Arrays
Median in O(log(m+n)) by partitioning.
23.Minimize Max Distance to Gas Station
Binary search the max adjacent distance after adding k stations.