About This Pattern
Master the Binary Search pattern by practicing these problems organized by difficulty.Focus on the Key Signals - these are the indicators that tell you when to use this pattern.
Easy (2)
Binary Search
Search for a target value in a sorted array using binary search.
Key Signals:
Sorted arrayO(log n) requiredDivide search space in half
First Bad Version
Find the first bad version using the isBadVersion API with minimum API calls.
Key Signals:
Find boundaryMinimize callsBinary search on answer
Medium (1)
Search a 2D Matrix
Search for a value in a 2D matrix where rows and columns are sorted.
Key Signals:
Treat as 1D sorted arrayConvert index to row/colTwo binary searches possible
Hard (1)
Median of Two Sorted Arrays
Find the median of two sorted arrays in O(log(m+n)) time.
Key Signals:
Partition both arraysBinary search on smaller arrayBalance partitions