Question DSA-SRCH-0032
EasyWhat is the output of this code?
a = [2, 4, 6, 8, 10, 12]
lo, hi, target, steps = 0, 5, 10, 0
while lo <= hi:
steps += 1
mid = (lo + hi) // 2
if a[mid] == target:
break
elif a[mid] < target:
lo = mid + 1
else:
hi = mid - 1
print(steps)
- A.
3
- B.
2
- C.
Sign up free to see the answer and a step-by-step explanation.