Problem of the day
For a string “qaacde”, This string has two same adjacent characters.
So, one possible way to rearrange the string is “qacade”. Now, this string does not have two adjacent characters that are the same.
The first line of input contains a single integer T, representing the number of test cases or queries to be run.
Then the T test cases follow.
The first line of each test case contains a string S.
For each test case, the output will be “Yes” if you have returned the correct answer, else it will be “No”.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
0 <= |S| <= 10^5
Time Limit: 1 sec
2
coding
abaab
Yes
Yes
For the first test case, the given string is “coding”. This string does not have two adjacent characters that are the same. So if we return “coding", then we will get an output as “Yes”.
For the second test case, the given string is “abaab”. This string has two adjacent characters that are the same i.e. abaab, So we can rearrange the string as “ababa”.Hence we return “ababa”, then we will get an output as "Yes”.
1
bbbbbb
Yes
For the first test case, the given string is “bbbbbb”. No matter how you rearrange characters of string , it will always remain the same as bbbbbb.So we return “not possible” as an answer, then we will get an output as ‘Yes”.