#K15851. Can Two Letter Swaps Form a Palindrome?
Can Two Letter Swaps Form a Palindrome?
Can Two Letter Swaps Form a Palindrome?
Given a string S consisting of lowercase letters, determine whether it is possible to form a palindrome by swapping exactly two characters (or by making no swap if the string is already a palindrome).
A palindrome is a string that reads the same backward as forward. A necessary and sufficient condition for a string to be rearranged into a palindrome is that the number of characters with odd frequency is at most one. In this problem, however, you are allowed to swap two letters. Under these circumstances, if the number of characters with odd frequency exceeds 2, then no single swap can fix the mismatch, and the answer will be "No". Otherwise, answer "Yes".
Note: A string that is already a palindrome is considered valid and the output should be "Yes".
The mathematical condition can be expressed as follows:
$$\text{Let } O = \{ c : count(c) \text{ is odd} \}. \text{ Then, if } |O| \le 2, \text{ output } "Yes"; \text{ otherwise, output } "No". $$inputFormat
The input consists of a single line containing the string S. The string is made up of only lowercase letters.
Example: abca
outputFormat
Output a single line containing either "Yes" or "No". "Yes" indicates that by swapping two letters, the string can become a palindrome (or it already is one), whereas "No" indicates it is not possible.
Example: Yes
## sampleabca
Yes