#C3413. Can Make Palindrome with One Swap?
Can Make Palindrome with One Swap?
Can Make Palindrome with One Swap?
You are given a binary string S. Your task is to determine whether it is possible to transform S into a palindrome by performing at most one swap between any two distinct positions in the string.
A string is called a palindrome if for every index \(i\) in \([0, n-1]\), the character satisfies \(S[i] = S[n-i-1]\). In other words, the string reads the same forwards and backwards.
Constraints:
- \(1 \leq |S| \leq 10^5\)
If it is possible to rearrange the string into a palindrome with at most one swap, output YES
; otherwise, output NO
.
inputFormat
The input consists of a single line containing a binary string S.
outputFormat
Print a single line containing either "YES" if the string can be transformed into a palindrome with at most one swap, or "NO" otherwise.## sample
110011
YES