You start at index 0. nums[i] is the maximum jump length from index i. Return the fewest jumps needed to reach the last index, or -1 if it is unreachable. A list with 0 or 1 elements needs 0 jumps.
For [2, 3, 1, 1, 4] the answer is 2 (jump 1 step to index 1, then 3 steps to the end).
The starter code updates every reachable index from every earlier index. It is correct but too slow for long lists.
Example 1
Input:
min_jumps([2, 3, 1, 1, 4])
Output:
2
Example 2
Input:
min_jumps([2, 3, 0, 1, 4])
Output:
2
0 <= len(nums) <= 2000000 <= nums[i] <= 100000No results yet
Run your code to check it against the examples, or submit to run every test.