The "Binary Searchable Numbers in an Unsorted Array interview question" is a subtle challenge about the mechanics of binary search. In a sorted array, every number is "searchable" (meaning a binary search will correctly find it). In an unsorted array, some numbers might still be "searchable" if they happen to be in a position that the binary search algorithm doesn't skip. A number at index is searchable if all elements to its left are smaller and all elements to its right are larger.
Google uses the "Binary Searchable Numbers in an Unsorted Array coding problem" to check if a candidate truly understands how binary search works, rather than just memorizing the code. It tests "Array interview pattern" skills, specifically the ability to use pre-calculation (prefix max and suffix min) to validate global properties in linear time.
This problem is solved using the Prefix Maximum and Suffix Minimum pattern.
prefix_max where prefix_max[i] is the maximum value from 0 to i-1.suffix_min where suffix_min[i] is the minimum value from i+1 to n-1.arr[i] is searchable if prefix_max[i] < arr[i] AND arr[i] < suffix_min[i].
Count how many indices satisfy both conditions.Array: [1, 3, 2]
The pattern of "is the greatest so far and the smallest yet to come?" is a very common interview technique. Practice using "Monotonic Stack" or "Prefix/Suffix arrays" to solve these types of "boundary" problems.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find the Number of Subarrays Where Boundary Elements Are Maximum | Hard | Solve | |
| Shortest Subarray to be Removed to Make Array Sorted | Medium | Solve | |
| 132 Pattern | Medium | Solve | |
| Maximum Score of a Good Subarray | Hard | Solve | |
| Buildings With an Ocean View | Medium | Solve |