Given two strings s1 and s2(call letters in uppercase). Check if it is possible to convert s1 to s2 by performing following operations.
1. Make some lowercase letters uppercase.
2. Delete all the lowercase letters.
Input : s1 = daBcd s2 = ABC Output : yes Explanation : daBcd -> dABCd -> ABC Convert a and b at index 1 and 3 to upper case, delete the rest those are lowercase. We get the string s2. Input : s1 = argaju s2 = RAJ Output : yes Explanation : argaju -> aRgAJu -> RAJ convert index 1, 3 and 4 to uppercase and then delete. All lowercase letters Input : s1 = ABcd s2= BCD Output : NO
Let DPi, j be 1 if it is possible to convert 1st i characters of s1 to j characters of s2, else DPi, j=0. Close observations gives us two conditions to deal with.
Initially DP0, 0=1, if DPi, j=1 then it is possible to check for next sets using following conditions.
1. If s1[i] in upper case is equal to s2[j] then it is possible to convert i+1 characters of s1 to j+1 characters of s2, hence DPi+1, j+1=1.
2. If s1[i] is in lower case, then it is possible to delete that element and hence i+1 characters can be converted to j characters of s2. Hence DPi+1, j=1.
If DPn, m=1, then it is possible to convert s1 to s2 by following conditions.
Below is the CPP illustration of the above approach.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Transform One String to Another using Minimum Number of Given Operation
- Minimum number of deletions and insertions to transform one string into another
- Check if it is possible to convert one string into another with given constraints
- Print all possible ways to convert one string into another string | Edit-Distance
- Minimum operations to transform given string to another by moving characters to front or end
- Check if permutaion of one string can break permutation of another
- Check if one string can be converted to another
- Find length of longest subsequence of one string which is substring of another string
- Transform string str1 into str2 by taking characters from string str3
- Maximum length prefix of one string that occurs as subsequence in another
- Print array of strings in sorted order without copying one string into another
- Minimum swaps required to convert one binary string to another
- Map every character of one string to another such that all occurrences are mapped to the same character
- Minimum cost to traverse from one index to another in the String
- Minimum number of subsequences required to convert one string to another
- Minimum number of subsequences required to convert one string to another using Greedy Algorithm
- Check if a string can be obtained by rotating another string 2 places
- Check if a string can be repeated to make another string
- Check if a string can be converted to another string by replacing vowels and consonants
- Check if a string can be obtained by rotating another string d places
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.