#K52497. Rearrange String to Palindrome
Rearrange String to Palindrome
Rearrange String to Palindrome
You are given an integer n representing the length of a string s and the string s itself. Your task is to rearrange the characters of s to form a palindrome if it is possible. If multiple palindromic arrangements exist, you may output any one of them. If it is not possible to form a palindrome, output NO
.
A palindrome is a string that reads the same backward as forward. Formally, a string s is a palindrome if:
[ s = s^R ]
where \( s^R \) denotes the reverse of \( s \). Remember that a valid palindrome can have at most one character that appears an odd number of times.
inputFormat
The input consists of two lines:
- The first line contains a single integer
n
, which is the length of the string. - The second line contains the string
s
of lengthn
composed of lowercase letters.
outputFormat
If it is possible to rearrange the string into a palindrome, output any valid palindromic string. Otherwise, output NO
(without quotes).
4
aabb
abba