#K38107. Palindrome Rearrangement with One Deletion and One Swap

    ID: 26125 Type: Default 1000ms 256MiB

Palindrome Rearrangement with One Deletion and One Swap

Palindrome Rearrangement with One Deletion and One Swap

You are given a string \(s\) consisting of lowercase English letters only. You must perform exactly two operations in order:

  • Delete exactly one character from \(s\).
  • Swap the characters at exactly two different positions in the remaining string.

After performing these operations, determine if it is possible for the resulting string to be rearranged into a palindrome. In other words, check if the frequency of characters (after one deletion) allows the string to form a palindrome (i.e. at most one character may have an odd frequency count).

If it is possible, output YES; otherwise, output NO.

Note: Even if the original string is already a palindrome, you are required to perform the two operations.

Example:

  • For \(s = \texttt{abca}\), by deleting one character (for instance, removing 'b') the string becomes \(\texttt{aca}\) which can be rearranged into a palindrome. Hence, the answer is YES.
  • For \(s = \texttt{abc}\), no such deletion will result in a valid frequency distribution for a palindrome. Thus, the answer is NO.
  • inputFormat

    The input consists of a single line containing a non-empty string (s) of lowercase English letters.

    outputFormat

    Output a single line containing either (YES) or (NO), indicating whether it is possible to obtain a palindrome (by rearrangement) after performing exactly one deletion and one swap operation.## sample

    a
    
    YES
    

    </p>