Dashboard
#62. Jump GameMediumGreedy

You are given an integer array nums where each element nums[i] indicates your maximum jump length at that position.

Return true if you can reach the last index starting from index 0, or false otherwise.

Example 1:

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

Output: true

Explanation: First jump from index 0 to 1, then from index 1 to 3, and lastly from index 3 to 4.

Example 2:

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

Output: false

Constraints:

  • 1 <= nums.length <= 1000
  • 0 <= nums[i] <= 1000
Examples
Example 1:
Input: nums = [1,2,0,1,0]
Output: true
Example 2:
Input: nums = [1,2,1,0,1]
Output: false
Constraints
  • `1 <= nums.length <= 1000`
  • `0 <= nums[i] <= 1000`
Target: O(N) time • O(1) spaceArray / Dynamic Programming / Greedy
Socratic AI Tutor
Gemini 3.8 Flash
Loading editor...

Click "Run" or press Ctrl+Enter to execute test cases.