Transform string str1 into str2 by taking characters from string str3 | C ++ program of the above approach ; Function to check whether str1 can be transformed to str2 ; To store the frequency of characters of string str3 ; Declare two pointers & flag ; Traverse both the string and check whether it can be transformed ; If both pointers point to same characters increment them ; If the letters don 't match check  if we can find it in string C ; If the letter is available in string str3 , decrement it 's  frequency & increment the ptr2 ; If letter isn 't present in str3[]  set the flag to false and break ; If the flag is true and both pointers points to their end of respective strings then it is possible to transformed str1 into str2 , otherwise not . ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void convertString ( string str1 , string str2 , string str3 ) { map < char , int > freq ; for ( int i = 0 ; str3 [ i ] ; i ++ ) { freq [ str3 [ i ] ] ++ ; } int ptr1 = 0 ; int ptr2 = 0 ; bool flag = true ; while ( ptr1 < str1 . length ( ) && ptr2 < str2 . length ( ) ) { if ( str1 [ ptr1 ] == str2 [ ptr2 ] ) { ptr1 ++ ; ptr2 ++ ; } else { if ( freq [ str3 [ ptr2 ] ] > 0 ) { freq [ str3 [ ptr2 ] ] -- ; ptr2 ++ ; } else { flag = false ; break ; } } } if ( flag && ptr1 == str1 . length ( ) && ptr2 == str2 . length ( ) ) { cout << " YES " << endl ; } else { cout << " NO " << endl ; } } int main ( ) { string str1 = " abyzfe " ; string str2 = " abcdeyzf " ; string str3 = " popode " ; convertString ( str1 , str2 , str3 ) ; return 0 ; }