Jump Game

Given an array nums where nums[i] represents the maximum jump length from index i, determine whether you can reach the last index starting from the first index. Pattern focus: Jump Game. Maintain the furthest reachable index so far; if the current position exceeds it, the answer is false.

Input Format

nums = maximum jump lengths at each index

Output Format

true if the last index is reachable

Constraints

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

Examples

Example 1:

Input:

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

Output:

true

Explanation:

You can jump 2 steps to index 2, then 2 more steps to the last index.

Example 2:

Input:

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

Output:

false

Explanation:

The zero at index 3 blocks progress before reaching the end.

Example 3:

Input:

nums = [2,0,0]

Output:

true

Explanation:

Jump directly from index 0 to the last index.

Loading...
Jump Game - Greedy DSA Problem