Jump Game

Greedy & Intervals, problem 3 of 8

Jump Game

Medium

LC #55

greedyarray

Not attempted yet

You start at index 0 of nums. From index i you may jump forward up to nums[i] steps.

Return True if you can reach the last index, otherwise False.

Example 1

Input: nums = [2,3,1,1,4]
Output: True

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

Example 2

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

Every path lands on index 3, whose jump length is 0.

Example 3

Input: nums = [0]
Output: True

You already stand on the last index.

Constraints

  • 1 <= nums.length <= 10^5
  • 0 <= nums[i] <= 10^5

Python

Loading draft…

Test results

8 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 5 hidden

Run examples, then submit all tests.