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 .
if ( flag && ptr1 == str1 . length ( ) && ptr2 == str2 . length ( ) ) { cout << " YES " << endl ; } else { cout << " NO " << endl ; } }