Google Interview Question
Software EngineersCountry: United States
Interview Type: In-Person
def bin_search(l,itm):
if len(l)== 0:
return False
else:
mid = len(l)//2
if l[mid] == itm:
return True
else:
if itm < l[mid]:
return(bin_search(l[:mid], itm))
else:
return(bin_search(l[mid+1:], itm))
tlist = [ -9, -1,0, 1, 2, 8,9, 13, 17, 19, 32, 42]
print(bin_search(tlist,8))
print(bin_search(tlist,0))
print(bin_search(tlist,29))
Thank you for the solution!
- Meghshyam November 01, 2018