The Search in a Sorted Array of Unknown Size interview question gives you a sorted integer array of unknown length accessible only through an API (ArrayReader.get(index) that returns a large sentinel value if the index is out of bounds). Your task is to find the target value and return its index using binary search, without knowing the array length upfront.
Microsoft and Google ask this interactive binary search problem because it tests the ability to adapt binary search to constrained API access — a common scenario in distributed systems, database query engines, and streaming data platforms where the full data size is unknown or expensive to compute. It evaluates both the search strategy and the exponential probe to find the right boundary.
The pattern is exponential expansion followed by binary search. First, find the search boundaries: start with left=0, right=1. Double right until reader.get(right) >= target (or hits the sentinel). This gives a range [left, right] that is guaranteed to contain the target if it exists. Then apply standard binary search within this range, treating sentinel values as "too large" and moving left.
Sorted array (unknown size): [1, 3, 5, 7, 11, 14, 18, 25]. Target = 14.
Exponential expansion:
Binary search in [4, 8]:
left during expansion — after expansion, left should be the previous right (not 0).For the Search in a Sorted Array of Unknown Size coding problem, the binary search and interactive interview pattern requires two phases: boundary finding and binary search. The key insight is exponential expansion — doubling right until you overshoot. Google interviewers appreciate candidates who explain why exponential expansion gives O(log n) total API calls for the boundary phase, the same asymptotic complexity as the binary search phase.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Number of Equal Numbers Blocks | Medium | Solve | |
| Find the Index of the Large Integer | Medium | Solve | |
| Find in Mountain Array | Hard | Solve | |
| Maximum Font to Fit a Sentence in a Screen | Medium | Solve | |
| Leftmost Column with at Least a One | Medium | Solve |