#C1913. One Character Palindrome
One Character Palindrome
One Character Palindrome
You are given a string s. Determine if it is possible to make the string a palindrome by removing at most one character. A palindrome is a string that reads the same backward as forward.
For example, given the string abca
, by removing the character c
the string becomes aba
, which is a palindrome. However, for the string abc
, no single removal will result in a palindrome.
Your task is to print True
if the string can be turned into a palindrome by removing at most one character, and False
otherwise.
Hint: You may consider the following condition mathematically: if for a string \( s \) with length \( n \), there exists an index \( i \) such that \( s[i] \neq s[n-i-1] \), then check if either the substring \( s[i+1 \ldots n-i-1] \) or \( s[i \ldots n-i-2] \) is a palindrome.
inputFormat
The input consists of a single line containing the string s.
outputFormat
Output a single line with True
if the string can be transformed into a palindrome by removing at most one character; otherwise, print False
.
abca
True