222. Jump Game
Medium
Greedy Reachability
Array
Problem
You are given an integer array nums where nums[i] represents the maximum jump length from index i. Return true if you can reach the final index starting from index 0.
Examples
Example 1
Input: [2,3,1,1,4]
Output: true
Example 2
Input: [3,2,1,0,4]
Output: false
Example 3
Input: [0]
Output: true
Constraints
� 1 <= nums.length <= 100000
� 0 <= nums[i] <= 100000
Hints
?? Track the farthest index reachable so far.
?? If the current index exceeds that boundary, the path is impossible.
Expected Complexity
Time: O(n)
Space: O(1)
Follow-up
Can you solve it greedily without dynamic programming?
Practice Notes
Attempts: 0
Time spent: 0min
Hints used: 0
JavaScript
00:00
Loading...
Case 1
Case 2
Case 3
Input
[2,3,1,1,4]Expected
true