Open AnuradhaPagare opened 10 hours ago
Control Abstraction for the same code.
Transform(s1, s2): m ← length of s1 n ← length of s2 Create a DP table dp[m+1][n+1]
// Base Case: Both strings are empty
dp[0][0] ← true
// Fill the DP table
for i from 1 to m:
for j from 0 to n:
// Case 1: Ignore the current character in s1 if it is lowercase
if isLowerCase(s1[i]):
dp[i][j] ← dp[i-1][j]
// Case 2: Match the character if possible
if j > 0 and toUpperCase(s1[i]) == s2[j]:
dp[i][j] ← dp[i][j] OR dp[i-1][j-1]
// Final decision
return dp[m][n]
Statement Given two strings s1 and s2 (all letters in uppercase). Check if it is possible to convert s1 to s2 by performing following operations.
Input: s1 = daBcd s2 = ABC Output: yes Input: s1 = argaju s2 = RAJ Output: yes
public class StringTransformation {
}