Searching · stretch
The first one big enough
items is sorted, possibly with repeats. Write first_at_least(items, x) returning the index of the first item >= x, or len(items) if there is none.
It is binary search that keeps going after a match: a match might not be the first one.
- right answers
- arguments left as they should be
- fast enough at scale
- without bisect, bisect_left, bisect_right, index
Run adds print(first_at_least([1, 3, 3, 3, 8], 3)) after your code, to try it.
Stuck on the idea rather than the code? The Binary search, the useful kind lesson walks through it.