


If we are given a string "aabb", then the possible solutions are:
(i) abab
(ii) baba
We can see no two adjacent characters are the same in both strings.
So both (i) and (ii) are valid solutions.
The first line of input contains a single integer 'T', representing the number of test cases.
The first and only line of each test case contains a string 'STR'.
For each test case, return the resultant string if it is possible to rearrange string else return "NO SOLUTION". Accordingly, CORRECT or INCORRECT will get printed on the screen.
You don’t have to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= N <= 10^4
Where ‘N’ is the length of the string.
Time limit: 1 sec
The steps are as follows:
The required string is possible only when the frequency of the most frequent character is less than or equal to half of the size of the given string.
We can check the above-stated fact. Let's say we have a string of length 10. And say the most frequent character is ‘a’. Then the best possible way to arrange is ‘a_a_a_a_a_’. Now we can see if the frequency of a is greater than 5 then we can not make the required string. So we are going to store the frequency of each character and sort it. Let's say we name this array ‘HASH’.
The steps are as follows:
5. First fill the remaining even positions as we do in 2 of step 4.
6. Now we can fill the remaining odd positions in any order with the remaining characters.