#C3999. Palindrome Formation with One Reverse Operation
Palindrome Formation with One Reverse Operation
Palindrome Formation with One Reverse Operation
Given a binary string (S) consisting only of 0s and 1s, determine whether it is possible to transform it into a palindrome by performing at most one reverse operation on any substring. A reverse operation means selecting a contiguous segment of the string and reversing its order.
A palindrome is a string that reads the same forwards and backwards.
The input starts with an integer (T) denoting the number of test cases, followed by (T) lines, each with a binary string (S). For each string, output "YES" if it is possible to form a palindrome under the given operation constraint, otherwise output "NO".
Note that if the string is already a palindrome, no operation is needed.
inputFormat
The first line contains an integer (T) (1 ≤ (T) ≤ 10^5) — the number of test cases. Each of the next (T) lines contains a non-empty binary string (S) consisting of characters '0' and '1'. The sum of lengths of all strings does not exceed 10^6.
outputFormat
For each test case, output a single line containing "YES" if it is possible to make the string a palindrome by performing at most one reverse operation, or "NO" otherwise.## sample
3
1100
1001
111000
YES
YES
NO
</p>