def busca(num, a, primeiro, ultimo):
meio = int((primeiro + ultimo) / 2)
if num == a[meio]:
return meio
elif num < a[meio]:
return busca(num, a, primeiro, meio)
else:
return busca(num, a, meio+1, ultimo)
arr = [int(x) for x in raw_input().split()]
tamArray = arr[0]
numQuery = arr[1]
arr = []
arr = [int(x) for x in raw_input().split()]
i = 0
while i < numQuery:
num = int(input())
try:
print(busca(num, arr, 0, tamArray-1))
except:
print(-1)
i += 1
This is the code. The moji question asks for the following entries: First entry: N and Q, where N is the number of numbers in the sorted array and Q the number of searches to perform.
Second entry: Array ordered
Next Q entries: numbers to look for.
For each search, return the position of the number in the vector (starting with 0) and, if it does not find it, return -1
This is the link for the exercise if anyone has any questions: link