#K93982. Almost Palindrome

    ID: 38540 Type: Default 1000ms 256MiB

Almost Palindrome

Almost Palindrome

Given a string S, determine whether it can become a palindrome by removing at most one character. A palindrome is a string that reads the same forward and backward. Formally, you need to check if there exists at most one index i such that when S[i] is removed, the resulting string is a palindrome.

Input Constraints:

  • S consists of printable characters.
  • S may be empty.

Examples:

  • S = "abca" → True
  • S = "abcdef" → False
  • S = "racecar" → True

The check should consider at most one removal to achieve a palindrome.

The key idea is using a two-pointer technique and when a mismatch is found, testing if the substring obtained by skipping either the left or right character is a palindrome.

Formal Specification:

Define isAlmostPalindrome(S) such that it returns True if

\[ \text{isAlmostPalindrome}(S) = \begin{cases} True, & \text{if } S \text{ is a palindrome or can be made one by removing one character},\\ False, & \text{otherwise.} \end{cases} \]

inputFormat

The input is read from standard input (stdin) and consists of a single line containing the string S.

outputFormat

Output to standard output (stdout) a single line: 'True' if the string S can be turned into a palindrome by removing at most one character, and 'False' otherwise.

## sample
abca
True