Check if all strings of an array can be made same by interchanging characters | Java Program to implement the above approach ; Function to check if all Strings are equal after swap operations ; Stores the frequency of characters ; Stores the length of String ; Traverse the array ; Traverse each String ; Check if frequency of character is divisible by N ; Driver Code
class GFG { static boolean checkEqual ( String arr [ ] , int N ) { int hash [ ] = new int [ 256 ] ; int M = arr [ 0 ] . length ( ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { hash [ arr [ i ] . charAt ( j ) ] ++ ; } } for ( int i = 0 ; i < 256 ; i ++ ) { if ( hash [ i ] % N != 0 ) { return false ; } } return true ; } public static void main ( String [ ] args ) { String arr [ ] = { " fdd " , " fhh " } ; int N = arr . length ; if ( checkEqual ( arr , N ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }