Faster binary search to find the index in Python?
I can see the problem with your code. Why This &quot;mid = right // 2  &quot; ?
You can try below code
def binarySearch(arr, low, high, key): 
    if high &gt;= low: 
        mid = (high + low) // 2
        if arr[mid] == key: 
            return mid 
        elif arr[mid] &gt; key: 
            return binarySearch(arr, low, mid - 1, key)
        else: 
            return binarySearch(arr, mid + 1, high, key)
    else:
        return -1