#C9799. Palindrome Permutation
Palindrome Permutation
Palindrome Permutation
You are given a string s
. Your task is to determine if any permutation of s
(ignoring spaces and case differences) can form a palindrome.
A palindrome is a sequence of characters that reads the same backward as forward. The key observation to solve this problem is that a string can be permuted into a palindrome if and only if at most one character appears an odd number of times. Formally, for a string s, after removing spaces and converting all letters to lowercase, if the frequency of characters satisfies the following condition, then some permutation of s can form a palindrome:
$$\text{Number of characters with odd frequency} \leq 1 $$For example, the string "carrace" can be rearranged as "racecar", which is a palindrome. However, "hello" cannot be rearranged into any palindrome. Your job is to implement this check.
inputFormat
The input is provided via standard input (stdin) and consists of a single line containing the string s
. The string may include spaces and both uppercase and lowercase letters.
outputFormat
Output a single line to standard output (stdout) containing YES
if any permutation of the given string can form a palindrome; otherwise, output NO
.
carrace
YES