How to use binary search to find if there is a distance between adjacent numbers greater than N in a sorted array? For instance:
Input: 2 5 8 11 16 Distance: 4
So, we must get an answer that there is such a distance between neighbors. (between 11 and 16)
EDIT: let me clarify why I want to do this using binary search.
Suppose the INPUT array is not sorted. Example:
Input: 11 8 2 16 5
Then you have to sort the array to see which of them are neighbors. So, after we have a sorted list, is not the best way to find the distance with some mutation of binary search?
source share