#C5848. Palindrome Formation by Removing At Most One Character
Palindrome Formation by Removing At Most One Character
Palindrome Formation by Removing At Most One Character
You are given a string S. Determine whether it is possible to obtain a palindrome by removing at most one character from S. A palindrome is a string that reads the same forwards and backwards.
Formally, you need to check if there exists an index i (possibly none) such that removing the character at the i-th position results in a string S' that satisfies
[ S' = reverse(S') ]
Note that if S is already a palindrome, it is considered valid.
For example, given the string "abca", by removing the character 'b' or 'c', you can obtain "aca" or "aba", which are palindromic. However, for the string "abc", no single removal can yield a palindrome.
inputFormat
The input consists of a single line containing the string S (1 ≤ |S| ≤ 105).
The string will consist only of lowercase English letters.
outputFormat
Print True
if it is possible to form a palindrome by removing at most one character; otherwise, print False
.
abca
True