SprintCode.pro

Подготовка к алгоритмическим задачам

Super

Jump Game

Description: Each element is the maximum jump length from that position. Starting at index 0, determine whether you can reach the last index.

Example 1:

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

Example 2:

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

Constraints:

1 <= nums.length <= 10⁴

0 <= nums[i] <= 10⁵

Recommended time and space complexity

Aim for O(n) time and O(1) space.


Hint 1

Exploring all jump combinations is exponential. One pass is enough.


Hint 2

Move left to right keeping the furthest reachable index.


Hint 3

If the current index exceeds the reachable maximum, there is no path.

A greedy algorithm problem. Teaches tracking the furthest reachable index instead of exploring all jump combinations.

Expected Input :

[2,3,1,1,4]

Expected Output

true