Jump Game

Medium

nums[i] is the maximum jump length from index i. Starting at index 0, return true if the last index can be reached.

Example 1

canJump()
Input
nums = [2,3,1,1,4]
Output
true

Why

Jump 1 step to index 1, then 3 steps to the end.

Example 2

canJump()
Input
nums = [3,2,1,0,4]
Output
false
Constraints
1 <= nums.length <= 10^4
0 <= nums[i] <= 10^5

Topics

ArraysGreedyDynamic Programming

Implement canJump in the editor and return the answer — printing it is never graded.