#K91757. Can an Anagram Form a Palindrome?
Can an Anagram Form a Palindrome?
Can an Anagram Form a Palindrome?
Given a non-empty string s
consisting of characters, determine if any anagram (i.e., any rearrangement of its letters) can form a palindrome.
A palindrome is a string that reads the same forwards and backwards. For an anagram to be a palindrome, at most one character can appear an odd number of times, while every other character must appear an even number of times. Formally, if we let \( f(c) \) denote the frequency of character \( c \) in the string, then the string can be rearranged to form a palindrome if and only if \[ \sum_{c}\mathbf{1}_{\{f(c) \text{ is odd}\}} \le 1. \]
Your task is to check this property and output YES if some anagram of s
forms a palindrome, otherwise output NO.
inputFormat
The input consists of a single line containing a non-empty string s
. The string may contain letters, digits, or other characters and its length is at least 1.
Input is read from standard input (stdin
).
outputFormat
Output a single line to standard output (stdout
) containing YES
if any anagram of s
can form a palindrome and NO
otherwise.
ivicc
YES