#K8681. Minimum Operations to Make a String Palindrome

    ID: 36947 Type: Default 1000ms 256MiB

Minimum Operations to Make a String Palindrome

Minimum Operations to Make a String Palindrome

You are given a string s and your task is to determine the minimum number of operations required to transform s into a palindrome. In one operation, you can change one character so that it matches its corresponding character in the mirrored position.

Formally, let the string be of length n. For each index i from 0 to \(\lfloor \frac{n}{2} \rfloor - 1\), if \(s[i] \neq s[n-i-1]\), you need one operation. The total number of operations is the sum of all such mismatches.

For example:

  • For s = "abba", no operation is needed because the string is already a palindrome.
  • For s = "ab", one operation is needed.
  • For s = "aaa", no operation is needed.

inputFormat

The input is read from stdin and consists of multiple test cases. The first line contains a single integer T denoting the number of test cases. Each of the following T lines contains a single string s.

Constraints:

  • s consists of only lowercase English letters.
  • The length of s is at least 0.

outputFormat

For each test case, output a single line containing the minimum number of operations required to convert the given string into a palindrome. The results should be printed to stdout.

## sample
3
abba
ab
aaa
0

1 0

</p>