Skip to content
Decoder

Jump Game

Medium

Problem

You stand on index 0 of nums. From index i you may jump forward up to nums[i] places. Return true if you can reach the last index.

Example 1

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

Example 2

Input
nums = [3, 2, 1, 0, 4]
Output
false
Why
every route lands on the 0 at index 3

Example 3

Input
nums = [0]
Output
true
Why
you start at the end

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.