#K61602. Reverse Substring to Form Palindrome
Reverse Substring to Form Palindrome
Reverse Substring to Form Palindrome
You are given a string S. Your task is to determine whether S can be transformed into a palindrome by performing at most one operation: reversing exactly one contiguous substring of S. Note that if S is already a palindrome, it is considered valid and no reversal is needed.
A string is a palindrome if it reads the same backward as forward. Formally, S is a palindrome if \(S = S^R\), where \(S^R\) denotes the reverse of S.
Input: A single string S.
Output: Output "YES" if it is possible to obtain a palindrome after at most one reversal operation, otherwise output "NO".
Example:
Input: 3 abca racecar abcdefg</p>Output: YES YES NO
inputFormat
The first line of input contains an integer \(T\) \( (T \ge 1) \) representing the number of test cases. Each test case consists of a single line containing the string \(S\). The string \(S\) may contain lowercase English letters.
Example:
3 abca racecar abcdefg
outputFormat
For each test case, output a single line containing "YES" if the string can be transformed into a palindrome by reversing at most one contiguous substring, or "NO" otherwise.
Example:
YES YES NO## sample
3
abca
racecar
abcdefg
YES
YES
NO
</p>