Solutions for Forming Palindrome

    • @AaronSkake
    • @Daniel, submitted in Python 3, achived 100% score
    
    import json
    def formpalin(s1,i,j,dp):
        if i>j:
            return 0
        if i==j:
            return 1
        if dp[i][j]!=-1:
            return dp[i][j]
        if s1[i]==s1[j]:
            dp[i][j]=2+formpalin(s1,i+1,j-1,dp)
        else:
            dp[i][j]=max(formpalin(s1,i+1,j,dp),formpalin(s1,i,j-1,dp))
        return dp[i][j]
    def solve(k):
        dp=[[-1]*len(k) for x in range(len(k))]
        res=len(k)-formpalin(k,0,len(k)-1,dp)
        return res