#K12286. Minimum Operations to Palindrome
Minimum Operations to Palindrome
Minimum Operations to Palindrome
You are given a string s
. In one operation, you can change a character so that it matches its corresponding character on the other end of the string. The goal is to transform the string into a palindrome with the minimum number of such operations. Formally, for a string of length n, the number of operations required is given by
where \(\mathbf{1}_{\{\cdot\}}\) is the indicator function. You need to compute this value for multiple test cases.
inputFormat
The first line of input contains an integer T
, the number of test cases. Each of the next T
lines contains a non-empty string s
.
outputFormat
For each test case, output a single integer on a new line representing the minimum number of operations required to transform the string into a palindrome.## sample
3
abc
abba
abcd
1
0
2
</p>