
1) He can swap any two characters of a string.
For example, “coding” -> “cgdino” i.e., swap ‘o’ with ‘g’.
2) He can change every occurrence of two existing characters into each other.
For example, “aababcc” -> “ccbcbaa” i.e., change all occurrences of ‘a’ into ‘c’ and ‘c’ into ‘a’.
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain two single space-separated strings ‘STR1’ and ‘STR2’ as mentioned above.
For each test case, print true if Naresh can make both the given strings equal. Otherwise, print false.
Output for every test case will be printed in a separate line.
You don’t need to print anything; It has already been taken care of.
1 <= T <= 50
1 <= |’STR1’|, |‘STR2’| <= 100000
‘STR1’ and‘STR2’ will only be composed of lowercase English alphabets.
Where ‘T’ is the number of test cases and |’STR1’| and |‘STR2’| are the lengths of strings ‘STR1’ and ‘STR2’.
Time limit: 1 sec
As we know we can swap any number of times. Hence ordering of characters does not matter. First, store the frequency of characters of both the strings in arrays/vectors ‘freq1’ and ‘freq2’. If there are some characters that are present in ‘STR1’ but not in ‘STR2’ and vice versa, then return false. Now we know both strings contain similar characters.
We know we can change every occurrence of two existing characters into each other.
So sort both the frequency arrays/vectors and check if ‘freq1[i]’ is equal to ‘freq2[i]’ or not.