#C3838. Palindrome Rearrangement
Palindrome Rearrangement
Palindrome Rearrangement
Given a string s
of length n
consisting only of lowercase English letters, determine if it is possible to rearrange the characters of s
to form a palindrome.
A string is a palindrome if it reads the same forward and backward. According to the well-known condition of palindromic permutations, a string can be rearranged to form a palindrome if and only if at most one character appears an odd number of times.
For instance, if s = "aabb"
, a palindrome can be formed (e.g., "abba"). However, if s = "abcde"
, it is impossible to rearrange the characters to meet the palindrome condition, hence the answer would be NO
.
Note: The problem only allows rearrangement of the characters (without removal or substitution), and the input integer n
represents the length of the string.
inputFormat
The input consists of two lines:
- The first line contains an integer
n
which is the length of the string. - The second line contains the string
s
consisting of only lowercase English letters.
outputFormat
Output a single line containing YES
if the string can be rearranged to form a palindrome, or NO
otherwise.
4
aabb
YES
</p>