Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
def locate_card(cards,query):
lo,hi=0,len(cards)-1
print('lo=',lo,'hi=',hi)
while lo<=hi:
mid=(lo+hi)//2
if cards[mid]==query:
return mid
elif cards[mid]< query:
hi=mid-1
elif cards[mid]>query:
lo = mid+1
return -1
from jovian.pythondsa import evaluate_test_cases
from jovian.pythondsa import evaluate_test_case
tests=[]
tests.append({
'input':{'cards':[15,14,10,9,7,6,3],
'query':10
},
'output':2
})