Suppose we have two strings s and t, t is in uppercase. We have to check whether we can convert s to t by performing following operations.
So, if the input is like s = "fanToM", t = "TOM", then the output will be True as we can change ‘o’ to ‘O’ then remove all other lowercase letters from s to make it t.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(s,t): n = len(s) m = len(t) dp= [[False for i in range(m+1)] for i in range(n+1)] dp = True for i in range(len(s)): for j in range(len(t)+1): if dp[i][j] == True: if j < len(t) and (s[i].upper() == t[j]): dp[i + 1][j + 1] = True if s[i].isupper()==False: dp[i + 1][j] = True return dp[n][m] s = "fanToM" t = "TOM" print(solve(s, t))