#K93447. Almost Palindrome

    ID: 38421 Type: Default 1000ms 256MiB

Almost Palindrome

Almost Palindrome

In this problem, you are given a non-empty string ( s ). Your task is to determine whether it is possible to make ( s ) a palindrome by removing at most one character. A string is a palindrome if it reads the same backward as forward. Formally, you need to decide if there exists an index ( i ) (or no index removal) such that the string formed by deleting the character at index ( i ) is a palindrome.

Examples:

  • Input: "ab" → Output: YES (remove either 'a' or 'b')
  • Input: "racecar" → Output: YES (already a palindrome)
  • Input: "palindrome" → Output: NO (cannot be converted by one removal)

Note: An empty string is considered a palindrome.

inputFormat

The input is read from standard input (stdin) and consists of multiple lines:

  • The first line contains a single integer \( T \), the number of test cases.
  • Each of the following \( T \) lines contains a string \( s \). The string may be empty.

For example:

5
ab
aa
racecar
palindrome
a

outputFormat

For each test case, output a single line to standard output (stdout) containing "YES" if the given string can be turned into a palindrome by removing at most one character, or "NO" otherwise.## sample

5
ab
aa
racecar
palindrome
a
YES

YES YES NO YES

</p>