#C9012. One Change Palindromic Permutation
One Change Palindromic Permutation
One Change Palindromic Permutation
You are given a string s
consisting of lowercase English letters. Your task is to determine if the string can be rearranged into a palindrome by changing at most one character. In other words, check if s
is either already a permutation of a palindrome, or if by removing exactly one character, the remaining characters can be rearranged into a palindrome.
A string is a permutation of a palindrome if at most one character appears an odd number of times. Formally, let odd_count be the number of characters with an odd frequency. Then, the string is a permutation of a palindrome if:
[ \text{odd_count} \le 1 ]
If the condition is not satisfied, you are allowed to remove one character from the string and test the condition again. If it holds after a single removal, output YES
; otherwise, output NO
.
Note: The solution should read the input from standard input (stdin) and print the output to standard output (stdout).
inputFormat
The input contains a single line with the string s
(1 ≤ |s| ≤ 105), consisting of lowercase letters.
outputFormat
Output YES
if the string can be rearranged into a palindrome by changing at most one character (i.e. by possibly removing one character), otherwise output NO
.
a
YES