click below for solution

Wednesday, 2 February 2022

Anti Palindrome Solution|Codesheff starter 24 for div 3

1

1-indexed) string S of length N is said to be anti-palindrome if, for each 1iNSiS(N+1i).

You are given a string S of length N (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 T — the number of test cases. The description of T test cases follows.
  • The first line of each test case contains an integer N — the length of the string S.
  • The second line of each test case contains the string S.

Output Format

For each test case, if it is possible to rearrange S 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. yesyEsYes will be considered identical).

If there are multiple rearrangements of the string which are anti-palindromic, print any of them.

Constraints

  • 1T104
  • 1N105
  • S contains only lowercase Latin letters
  • It is guaranteed that the sum of N over all test cases does not exceed 2105.

Sample Input 1 

4
3
abc
8
abccccdd
4
xyyx
6
ppppqr

Sample Output 1 

NO
YES
abddcccc
YES
xxyy
NO

Explanation

Test case 1: No matter how the string is rearranged, the condition SiS(N+1i) will not be satisfied for i=2.

Test case 2: One possible rearrangement of the string which is anti-palindromic is abddcccc. Other answers, such as ccdaccdb, will also be accepted.

Test case 3: One possible rearrangement of the string which is anti-palindromic is xxyy.

Test case 4: It can be shown that none of the rearrangements of A 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

https://shrinke.me/0joa

Solution link 3

https://afly.pro/4dPM5oi

Solution link 4

https://afly.pro/X6gV2u4

How to get link tutorial video link

https://youtu.be/0TSsPHhgwb4


No comments:

Post a Comment