FunctionRacerProblemsRace

Fewest Jumps to the End

MediumGreedyPython, JavaScript, TypeScript, Java, C++

You stand on index 0 of nums. From index i you may jump forward by any distance from 1 up to nums[i].

Return the fewest jumps needed to reach the last index. The last index can always be reached in the tests.

Example 1

nums [2,3,1,1,4]
returns 2

Jump to index 1, then to the end: 2 jumps.

Example 2

nums [1]
returns 0

Already at the end: 0 jumps.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Greedy problems