/55. Jump Game

55. Jump Game

Medium
Arrays40.6% acceptance

Given an integer array jump_lengths, where each element represents the maximum number of indices you can move forward from that position, determine if it is possible to reach the last index starting from the first index. Return True if possible, otherwise return False.

Example 1

Input: [5,0,0,0,0,0]

Output: True

Explanation: The first element allows jumping directly to the last index.

Example 2

Input: [1,1,1,1,0]

Output: True

Explanation: Each step moves forward by 1, and the last index is reached.

Example 3

Input: [0,2,3]

Output: False

Explanation: Cannot move from the first index.

Constraints

  • 1 <= len(jump_lengths) <= 10_000
  • 0 <= jump_lengths[i] <= 100_000 for all valid i
Python (current runtime)

Case 1

Input: [2,0,2,0,1]

Expected: True

Case 2

Input: [1,0,0,0]

Expected: False

Case 3

Input: [3,2,1,0,0]

Expected: True

Case 4

Input: [0]

Expected: True

Case 5

Input: [4,1,1,0,0,0]

Expected: False