view grok_interview/binary_search.py @ 62:ea9ef388ab97

[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
author June Park <parkjune1995@gmail.com>
date Tue, 23 Dec 2025 11:48:11 -0800
parents 68fa88ac73fe
children
line wrap: on
line source


x = [1,2,3,4,5,9,20,25,33,99]
#    |          |

target  = 18
left = 0
right = len(x)

while left < right:
    mid = (left + right)//2
    if x[mid] == target:
        break
    elif x[mid] < target:
        left = mid + 1
    else:
        right = mid

print(x[mid])