Facebook PixelJump Game — Coding Practice
Jump GameMedium

Jump Game

Medium 17.6k38% acceptance
ArrayDynamic ProgrammingGreedy

You are given an integer array nums. You start at index 0, and each element nums[i] is the maximum number of steps you can jump forward from index i.

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

Example 1
Input: nums = [2,3,1,1,4]
Output: true
Jump 1 step to index 1, then 3 steps to the last index.
Example 2
Input: nums = [3,2,1,0,4]
Output: false
Every route stalls at index 3 (value 0), which is as far as you can get, and you cannot pass it to reach the end.
Example 3
Input: nums = [0]
Output: true
You already start on the last index.
Constraints
  • 1 ≤ nums.length ≤ 10⁴
  • 0 ≤ nums[i] ≤ 10⁵
Asked atAmazonGoogleMicrosoftMeta
JavaScript
Loading editor…
Case 1
[2,3,1,1,4]
expected: true
Case 2
[3,2,1,0,4]
expected: false
Case 3
[0]
expected: true
Case 4
[2,0,0]
expected: true
Case 5
[1,0,1,0]
expected: false
Case 6
[5,9,3,2,1,0,2,3,3,1,0,0]
expected: true
Case 7
[1,1,0,1]
expected: false