Is there a function in that uses binary search, like lower_bound but that returns the last item less-than-or-equal-to according to a given predic
lower_bound
A simple implementation in Python:
def bi_search(arr, target): """ index of the last element which <= target """ lo, hi = 0, len(arr) while lo < hi: mid = lo + (hi - lo) // 2 if arr[mid] <= target: lo = mid + 1 else: hi = mid return lo - 1