dsa · medium

Jump Game

You start at index 0 of nums. From index i you may jump at most nums[i] steps forward. Return whether you can reach the last index.

Arguments

Example

[2,3,1,1,4]true (0 → 1 → 4).

[3,2,1,0,4]false (the 0 traps you before the end).

Constraints

1 <= nums.length <= 4*10^4 0 <= nums[i] <= 10^5 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[2,3,1,1,4]

Expected:
true

Example 2

Input:
[3,2,1,0,4]

Expected:
false

Open in the Dojo editor