Skip to main content

Jump Game

Definition​

The Jump Game Algorithm determines if it's possible to reach the last index of an array starting from the first index, given that each element in the array represents the maximum number of steps that can be taken from that position

Practice​

canReachEnd(nums):
max_reachable = 0
for i from 0 to length(nums) - 1:
if i > max_reachable:
return false
max_reachable = max(max_reachable, i + nums[i])
if max_reachable >= length(nums) - 1:
return true
return false