Question DSA-SRCH-0041
MediumWhat is the output of this code?
a = [2, 5, 8, 12, 16, 23, 38, 56, 72, 91]
lo, hi, steps = 0, len(a) - 1, 0
while lo <= hi:
mid = (lo + hi) // 2
steps += 1
if a[mid] == 23:
break
if a[mid] < 23:
lo = mid + 1
else:
hi = mid - 1
print(mid, steps)
- A.
4 3
- B.
5 2
- C.
Sign up free to see the answer and a step-by-step explanation.