-indexed) string of length is said to be anti-palindrome if, for each , .
You are given a string of length (consisting of lowercase Latin letters only). Rearrange the string to convert it into an anti-palindrome or determine that there is no rearrangement which is an anti-palindrome.
If there are multiple rearrangements of the string which are anti-palindromic, print any of them.
Input Format
- The first line of input contains a single integer — the number of test cases. The description of test cases follows.
- The first line of each test case contains an integer — the length of the string .
- The second line of each test case contains the string .
Output Format
For each test case, if it is possible to rearrange to convert it into an anti-palindrome, print YES
in the first line and print the rearranged string in the second line. Otherwise, print NO
.
You may print each character of YES
and NO
in uppercase or lowercase (for e.g. yes
, yEs
, Yes
will be considered identical).
If there are multiple rearrangements of the string which are anti-palindromic, print any of them.
Constraints
- contains only lowercase Latin letters
- It is guaranteed that the sum of over all test cases does not exceed .
Sample Input 1
4
3
abc
8
abccccdd
4
xyyx
6
ppppqr
Sample Output 1
NO
YES
abddcccc
YES
xxyy
NO
Explanation
Test case : No matter how the string is rearranged, the condition will not be satisfied for .
Test case : One possible rearrangement of the string which is anti-palindromic is abddcccc
. Other answers, such as ccdaccdb
, will also be accepted.
Test case : One possible rearrangement of the string which is anti-palindromic is xxyy
.
Test case : It can be shown that none of the rearrangements of is anti-palindromic.
Solution:
solution link 1
https://shareus.in/?i=yScFNErxQ
if 1st link is not work then click on another link
Solution link 2
Solution link 3
Solution link 4
How to get link tutorial video link
No comments:
Post a Comment