Use Binary Search to find the first/last element with a property in a sorted array.
l: first position in your consideration
h: last position in your consideration, even can larger than the last index of the array
|
|
The idea is that if the mid point satisfies a property, then keep the opposite bound of round at mid, otherwise move the corresponding bound toward mid exceed 1.
Finally its true that l == h