Predict the output
What does this print?
hops = [3, 2, 1, 0, 4]
reach = 0
for i, h in enumerate(hops):
if i > reach:
print("stuck at", i)
break
reach = max(reach, i + h)
else:
print("made it")Choose an answer, then open Show answer below to check it.
Show answer
Answer: A stuck at 4
Right: every route lands on tile 3, which has a hop of 0.
Reachable tiles always form one unbroken prefix, so one value tracks them all.
Why not the others?
- B made it. Tile 4 is never reachable here.
- C stuck at 3. Tile 3 itself is reachable; it is tile 4 that is not.