Blind 75
62 / 75Free practice

Jump Game

Medium · Greedy

Jump to code

Each nonnegative array value is the maximum jump length allowed from that index. Starting at index 0, determine whether you can reach the final index of a nonempty array.

Examples

Example 1

nums = [2,3,1,1,4]

Output: true

Example 2

nums = [3,2,1,0,4]

Output: false

Constraints

  • 1 <= nums.length <= 1000
  • 0 <= nums[i] <= 1000
Need a hint?

Track the farthest reachable index rather than committing to a particular jump.

Asked in real interviews

Candidates reported versions of Jump Game from these company interviews. Some company questions are locked and open with Premium or XP.

Browse all real coding interview questions

Accepted submissions mark this problem complete. Progress stays in this browser.

Run checks 5 examples. Submit checks all 7 cases. A free account runs this problem; no XP needed.
Language
Case 1
Input
[
  [
    2,
    3,
    1,
    1,
    4
  ]
]
Expected
true
Case 2
Input
[
  [
    3,
    2,
    1,
    0,
    4
  ]
]
Expected
false
Case 3
Input
[
  [
    0
  ]
]
Expected
true
Case 4
Input
[
  [
    2,
    0,
    0
  ]
]
Expected
true
Case 5
Input
[
  [
    1,
    0,
    1,
    0
  ]
]
Expected
false

Drafts are saved per language in this browser when storage is available.