Solutions for Longest Similar Subsequence

    • @TerryDic
    • @Robert, submitted in Python 2, achived 100% score
    def lcs(X, Y,m,n):
        if m == 0 or n == 0:
            return 0
        elif X[m-1] == Y[n-1]:
            return 1 + lcs(X, Y, m-1, n-1);
        else:
            return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n));
    def solve(X,Y):
        r=lcs(X,Y,len(X),len(Y))
        return r
    
    
    
    • @TerryDic
    • @Robert, submitted in Python 3, achived 100% score
    def lcs(X, Y,m,n):
        if m == 0 or n == 0:
            return 0
        elif X[m-1] == Y[n-1]:
            return 1 + lcs(X, Y, m-1, n-1);
        else:
            return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n));
    def solve(X,Y):
        r=lcs(X,Y,len(X),len(Y))
        return r