Determine whether you can reach the last index of an array by making jumps from each position.
Problem
You are given a 0-indexed integer array nums. Each element nums[i] represents the maximum number of steps you can jump forward from index i.
Starting at index 0, determine whether it is possible to reach the last index of the array.
Return true if the last index is reachable, otherwise return false.
Notes
- You may jump any number of steps from
1tonums[i]. - You only move forward.
- Reaching the last index exactly counts as success.
Input Format
- An integer array
numswherenums[i]is the maximum forward jump length from indexi.
Output Format
- Return a boolean indicating whether index
nums.length - 1is reachable from index0.
Constraints
1 <= nums.length0 <= nums[i]- The array length and values are assumed to fit typical interview/online-judge limits.
Example 1
Input
nums = [2,3,1,1,4]
Output
true
Explanation
From index 0, jump to index 1, then jump to the last index.
Example 2
Input
nums = [3,2,1,0,4]
Output
false
Explanation
You can reach index 3, but nums[3] = 0 prevents reaching index 4.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.