Skip to content
BASA DSA

Jump Game

MediumGreedy

Starting at index zero, nums[i] is your maximum forward jump length from i. Return whether you can reach the final index.

Example 1

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

Explanation

Jump from 0 to 1, then use reach 3 to land at final index 4.

Example 2

Input
nums = [3,2,1,0,4]
Output
false

Explanation

No reachable index can jump beyond the zero at index 3.

Example 3

Input
nums = [0]
Output
true

Explanation

The sole starting index is already the finish.

Constraints

  • 1 <= len(nums) <= 10000
  • Values are 0..100000

Function contractcanJumpArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…