Update appNew update is available. Click here to update.

Rearrange string

Last Updated: 19 Dec, 2020
Difficulty: Hard

PROBLEM STATEMENT

Try Problem

You are given a string “S”. Your task is to rearrange the characters of a string “S”, such that it does not contain any two adjacent characters which are the same.

If it is possible to rearrange the string “S”, then print any possible arrangement. else, print “not possible” without quotes.

For Example:

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. 
Input format :
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.
Output format :
For each test case, the output will be “Yes” if you have returned the correct answer, else it will be “No”.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 10    
0 <= |S| <= 10^5 

Time Limit: 1 sec