Jump Game - Problem
You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.
Return true if you can reach the last index, or false otherwise.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [2,3,1,1,4]
›
Output:
true
💡 Note:
Jump 1 step from index 0 to 1, then 3 steps to the last index. Or jump 2 steps from index 0 to 2, then 1 step to index 3, then 1 step to the last index.
Example 2 — Impossible Case
$
Input:
nums = [3,2,1,0,4]
›
Output:
false
💡 Note:
You will always arrive at index 3. Its maximum jump length is 0, so you cannot proceed further to reach the last index.
Example 3 — Single Element
$
Input:
nums = [0]
›
Output:
true
💡 Note:
Already at the last index, no jumping needed.
Constraints
- 1 ≤ nums.length ≤ 104
- 0 ≤ nums[i] ≤ 105
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array where each element is max jump length
2
Process
Track farthest position reachable
3
Output
True if last index is reachable, false otherwise
Key Takeaway
🎯 Key Insight: Track the maximum reachable position greedily in one pass
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code