Jump Game

You are given an integer array nums. You are initially positioned at the first index, and each element nums[i] represents your maximum jump length from index i.

Return true if you can reach the last index, or false otherwise.

Example 1
Inputnums = [2,3,1,1,4]
Outputtrue
Starting at index 0, jump 1 step to index 1, then jump 3 steps to reach the last index.
Example 2
Inputnums = [3,2,1,0,4]
Outputfalse
No matter how you jump, you will arrive at index 3 where nums[3] is 0 and cannot move past it to the last index.

Constraints

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

Asked at 34 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate