Minimum jumps to the end
Return the fewest jumps to reach the final index, or -1 if impossible. Values are nonnegative maximum jump lengths. Empty input returns -1.
layer_end, farthest = 2, 4
print(farthest > layer_end) # another layerReason about the state
Treat each reachable interval as a breadth-first layer. Finish a layer before increasing the jump count and reject a frontier that cannot advance. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return the fewest jumps to reach the final index, or -1 if impossible. Values are nonnegative maximum jump lengths. Empty input returns -1.
The explanation opens here once every check passes.