15. Two indexes move toward each other.
v = [1, 4, 6, 9, 12]
lo, hi = 0, len(v) - 1
steps = 0
while lo < hi:
if v[lo] + v[hi] == 15:
break
if v[lo] + v[hi] < 15:
lo += 1
else:
hi -= 1
steps += 1
print(lo, hi, steps)
What does the program print?Log in to join the discussion.
Loading…