Solutions for Fix student name string matching challenge

    • @
    • @Zafir, submitted in Python 2, achived 100% score
    # Complete the abbreviation function below.
    def solve(a, b):
        n=len(a)
        m=len(b)
        dp=[[0]*(m+1) for _ in range(n+1)]
        dp[0][0]=1
        i=1
        while i<n+1:    
            if a[i-1].isupper():
                break
            else:
                dp[i][0]=1
            i+=1
        for i in range(1,n+1):
            for j in range(1,m+1):
                if a[i-1]==b[j-1]:
                    dp[i][j]=dp[i-1][j-1]
                elif a[i-1].islower() and a[i-1].upper()==b[j-1]:
                    dp[i][j]=dp[i-1][j-1] or dp[i-1][j]
                elif a[i-1].isupper():
                    dp[i][j]=0
                else:
                    dp[i][j]=dp[i-1][j]
        return  "can be modified" if dp[-1][-1] else "cannot be modified"
    
    • @JavierVow
    • @jacob, submitted in Python 2, achived 100% score
    # Complete the abbreviation function below.
    def solve(a, b):
        n=len(a)
        m=len(b)
        dp=[[0]*(m+1) for _ in range(n+1)]
        dp[0][0]=1
        i=1
        while i<n+1:    
            if a[i-1].isupper():
                break
            else:
                dp[i][0]=1
            i+=1
        for i in range(1,n+1):
            for j in range(1,m+1):
                if a[i-1]==b[j-1]:
                    dp[i][j]=dp[i-1][j-1]
                elif a[i-1].islower() and a[i-1].upper()==b[j-1]:
                    dp[i][j]=dp[i-1][j-1] or dp[i-1][j]
                elif a[i-1].isupper():
                    dp[i][j]=0
                else:
                    dp[i][j]=dp[i-1][j]
        return  "can be modified" if dp[-1][-1] else "cannot be modified"
    
    • @JavierVow
    • @jacob, submitted in Python 3, achived 100% score
    # Complete the abbreviation function below.
    def solve(a, b):
        n=len(a)
        m=len(b)
        dp=[[0]*(m+1) for _ in range(n+1)]
        dp[0][0]=1
        i=1
        while i<n+1:    
            if a[i-1].isupper():
                break
            else:
                dp[i][0]=1
            i+=1
        for i in range(1,n+1):
            for j in range(1,m+1):
                if a[i-1]==b[j-1]:
                    dp[i][j]=dp[i-1][j-1]
                elif a[i-1].islower() and a[i-1].upper()==b[j-1]:
                    dp[i][j]=dp[i-1][j-1] or dp[i-1][j]
                elif a[i-1].isupper():
                    dp[i][j]=0
                else:
                    dp[i][j]=dp[i-1][j]
        return  "can be modified" if dp[-1][-1] else "cannot be modified"