Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you are able to reach the last index. Tags: Dynamic Programming
Try It!
Discussion
Video
Solution
class Solution:
def canJump(self, nums: List[int]) -> bool:
reachable = 0
for i in range(len(nums)):
if i > reachable:
return False
reachable = max(reachable, i + nums[i])
return True