#K59727. Valid Palindrome with At Most One Removal
Valid Palindrome with At Most One Removal
Valid Palindrome with At Most One Removal
You are given a string \(s\) and your task is to determine whether it is possible to make \(s\) a palindrome by removing at most one character. A palindrome is a string that reads the same forwards and backwards. Formally, for a string \(s\) of length \(n\), it is a palindrome if \(s[i] = s[n-i-1]\) for every \(0 \leq i < n\). You are allowed to remove at most one character from \(s\) to achieve this condition.
Example:
- Input: "abca" — Remove the character 'c' to obtain "aba", which is a palindrome.
- Input: "stone" — It is not possible to obtain a palindrome by removing just one character.
Use standard input and output for interacting with the program.
inputFormat
The input consists of a single line containing the string \(s\). The string may be empty and can contain any printable characters.
outputFormat
Output a single line: True
if the string can become a palindrome by removing at most one character, otherwise output False
.
abca
True