If from each box you can jump forward at most values[i], can you get to the end? You do not have to decide which box to jump to. Carry one number: the farthest box I can reach so far. If you can reach a box, you can reach every box before it too.
reach = 0for i, jump in enumerate(values):if i > reach:return Falsereach = max(reach, i + jump)return True
i + jump).The same idea meets you on a grid as the rule "go to the nearest target": collecting the nearest each time is usually a good plan and easy to work out. Mind the word "usually": nearest does not guarantee the shortest total way; with limited energy you have to measure it.