题目如下:
We are given an unsorted array of n distinct elements, and use binary search to find a specific number. How many numbers are guaranteed to be able to be found using binary search in the array?
Given [2, 1, 3, 4, 6, 5] and target = 5, we cannot find 5. Because when the random index is 4, we get element 6, then right pointer will move left, so we’ll lose the opportunity to find target 5.
Given [2, 1, 3, 4, 5, 6] and target = 5, we can find 5. Because wherever the random index picks, we’ll find target at last.
Example 1:
Input: [2, 1, 3, 5, 4, 6]
Output: 2
Explanation: 3 and 6 are the numbers guaranteed to be found.
Example 2:
Input: [1, 2, 3]
Output: 3
Explanation: all the numbers guaranteed to be found.
Example 3:
Input: [3, 2, 1]
Output: 0
Explanation: no numbers guaranteed to be found.