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 ( ) ) { System . out . print ( " YES " + "NEW_LINE"); } else { System . out . print ( " NO " + "NEW_LINE"); } }