Check if it possible to jump to last position of Array

Check if it possible to to jump to last position of Array

Check if it possible to jump to last position of Array

Given an array with positive integers as elements indicating the maximum length of a jump which can be made from any position in the array.

Check if it is possible to have a jumps combination so that you can eventually reach the end of given array. Print “true” if it is possible, otherwise, print “false”.

Code Solution:

#Check if it possible to jump to last position of Array

nums=[0,2,4]
l=len(nums)-1
f=False
for i in range(l+1):
    if nums[i]+i>=l:
        f=True;
    else:
        i+=nums[i]
    if nums[i]==0 and i<l:
        f=False
        break
print(f) 

#Check if it possible to jump to last position of Array

Leave a Comment