Java program to implement the above approach
import java . util . * ; import java . io . * ; class GFG { public static String rev ( String str ) { int st = 0 ; int ed = str . length ( ) - 1 ; char [ ] s = str . toCharArray ( ) ; while ( st < ed ) { char temp = s [ st ] ; s [ st ] = s [ ed ] ; s [ ed ] = temp ; st ++ ; ed -- ; } return ( s . toString ( ) ) ; } public static boolean check ( String a , String b , int n ) { int i = 0 ; int j = n - 1 ;