sorted_index()
Determines the lowest index at which `value` should be inserted into `array` in order to maintain its sorted order.
Implementation
Args: array: A list of elements that are already sorted. value: The value to be inserted. Returns: The index at which `value` should be inserted to keep the array sorted.
Example
sorted_index([1, 2, 2, 3, 4], 2)
Expected output: 1
Source Code
def sorted_index(array: List[T], value: T) -> int:
return bisect.bisect_left(array, value) # type: ignore