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
Jump Game: Can You Reach the End?2311401234Start hereGoal: Reach here!Each number = maximum jump length from that positionMultiple paths exist → Output: true
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
Asked in
Google 45 Amazon 38 Microsoft 32 Meta 28
78.0K Views
High Frequency
~15 min Avg. Time
2.1K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen