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
function convertString ( str1 , str2 , str3 ) { let freq = new Map ( ) ; for ( let i = 0 ; i < str3 . length ; i ++ ) { if ( freq . has ( str3 [ i ] ) ) freq . set ( str3 [ i ] , freq . get ( str3 [ i ] ) + 1 ) ; else freq . set ( str3 [ i ] , 1 ) ; } let ptr1 = 0 ; let ptr2 = 0 ; let flag = true ; while ( ptr1 < str1 . length && ptr2 < str2 . length ) { if ( str1 [ ptr1 ] == str2 [ ptr2 ] ) { ptr1 ++ ; ptr2 ++ ; } else { if ( freq . has ( str3 [ ptr2 ] ) ) if ( freq . get ( str3 [ ptr2 ] ) > 0 ) { freq . set ( str3 [ ptr2 ] , freq . get ( str3 [ ptr2 ] ) - 1 ) ; ptr2 ++ ; } else { flag = false ; break ; } } } if ( flag && ptr1 == str1 . length && ptr2 == str2 . length ) { document . write ( " " + " " ) ; } else { document . write ( " " + " " ) ; } } let str1 = " " ; let str2 = " " ; let str3 = " " ; convertString ( str1 , str2 , str3 ) ;