Map every character of one string to another such that all occurrences are mapped to the same character | Java implementation of the approach ; Function that returns true if the mapping is possible ; Both the strings are of un - equal lengths ; To store the frequencies of the characters in both the string ; Update frequencies of the characters ; For every character of s1 ; If current character is not present in s1 ; Find a character in s2 that has frequency equal to the current character 's  frequency in s1 ; If such character is found ; Set the frequency to - 1 so that it doesn 't get picked again ; Set found to true ; If there is no character in s2 that could be mapped to the current character in s1 ; Driver code
class GFG { static int MAX = 26 ; public static boolean canBeMapped ( String s1 , int l1 , String s2 , int l2 ) { if ( l1 != l2 ) return false ; int [ ] freq1 = new int [ MAX ] ; int [ ] freq2 = new int [ MAX ] ; for ( int i = 0 ; i < l1 ; i ++ ) freq1 [ s1 . charAt ( i ) - ' a ' ] ++ ; for ( int i = 0 ; i < l2 ; i ++ ) freq2 [ s2 . charAt ( i ) - ' a ' ] ++ ; for ( int i = 0 ; i < MAX ; i ++ ) { if ( freq1 [ i ] == 0 ) continue ; boolean found = false ; for ( int j = 0 ; j < MAX ; j ++ ) { if ( freq1 [ i ] == freq2 [ j ] ) { freq2 [ j ] = - 1 ; found = true ; break ; } } if ( ! found ) return false ; } return true ; } public static void main ( String [ ] args ) { String s1 = " axx " ; String s2 = " cbc " ; int l1 = s1 . length ( ) ; int l2 = s2 . length ( ) ; if ( canBeMapped ( s1 , l1 , s2 , l2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }