Python 3 Iterative DP


#1

Here you go, Happy coding :slight_smile:

class Solution:

# @param A : list of integers
# @return an integer

def canJump(self, A):
    L=len(A)
    if len(A)==1:
        return 1
        
    dp=[None for i in range(len(A))]
    
    dp[len(A)-1]=99 #ANY VALUE OTHER THAN 0 and 1
    
    for i in range(len(A)-2,-1,-1):
        
        if A[i]==0:
            dp[i]=0
            
        else:
            for j in range(A[i]):
                try:
                    
                    if dp[i+j+1]==1 :
                        dp[i]=1
                        break
                    
                    elif A[i]+i>=L:
                        dp[i]=1
                        break
                    
                    else:
                        dp[i]=0
                        
                except:
                    continue
            
            
    return dp[0]