Transform string str1 into str2 by taking characters from string str3 | 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
def convertString ( str1 , str2 , str3 ) : NEW_LINE INDENT freq = { } NEW_LINE for i in range ( len ( str3 ) ) : NEW_LINE INDENT if ( freq . get ( str3 [ i ] ) == None ) : NEW_LINE INDENT freq [ str3 [ i ] ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT freq . get ( str3 [ i ] , 1 ) NEW_LINE DEDENT DEDENT ptr1 = 0 NEW_LINE ptr2 = 0 ; NEW_LINE flag = True NEW_LINE while ( ptr1 < len ( str1 ) and ptr2 < len ( str2 ) ) : NEW_LINE INDENT if ( str1 [ ptr1 ] == str2 [ ptr2 ] ) : NEW_LINE INDENT ptr1 += 1 NEW_LINE ptr2 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT if ( freq [ str3 [ ptr2 ] ] > 0 ) : NEW_LINE INDENT freq [ str3 [ ptr2 ] ] -= 1 NEW_LINE ptr2 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT flag = False NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT if ( flag and ptr1 == len ( str1 ) and ptr2 == len ( str2 ) ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str1 = " abyzfe " NEW_LINE str2 = " abcdeyzf " NEW_LINE str3 = " popode " NEW_LINE convertString ( str1 , str2 , str3 ) NEW_LINE DEDENT