#K2861. One-Reversal Palindrome Transformation
One-Reversal Palindrome Transformation
One-Reversal Palindrome Transformation
You are given a string s
and you need to determine whether it can be transformed into a palindrome by reversing exactly one substring.
A palindrome is a string that reads the same forwards and backwards. In this problem, if the string is already a palindrome, then the answer is True
. Otherwise, you are allowed to choose one contiguous substring and reverse it. If it is possible to obtain a palindrome by this single operation, print True
; otherwise, print False
.
More formally, for a given string \( s \) of length \( n \), find if there exists indices \( i, j \) (with \( 0 \le i \le j < n \)) such that if the substring \( s[i \ldots j] \) is reversed, the resulting string is a palindrome. If such a pair exists, output True
, otherwise output False
.
inputFormat
The input consists of a single line containing a non-empty string s
.
You should read the string from stdin
.
outputFormat
Output a single line with True
if it is possible to transform the string into a palindrome by reversing exactly one substring, otherwise output False
. The answer should be written to stdout
.
radkar
True