Question DSA-SRCH-0015
HardWhat is the output of this code?
a, t = [4, 5, 6, 7, 0, 1, 2], 0
lo, hi = 0, len(a) - 1
ans = -1
while lo <= hi:
mid = (lo + hi) // 2
if a[mid] == t:
ans = mid
break
if a[lo] <= a[mid]:
if a[lo] <= t < a[mid]:
hi = mid - 1
else:
lo = mid + 1
else:
if a[mid] < t <= a[hi]:
lo = mid + 1
else:
hi = mid - 1
print(ans)
- A.
4
- B.
6
- C.
Sign up free to see the answer and a step-by-step explanation.