#K54442. Minimum Steps to Palindrome
Minimum Steps to Palindrome
Minimum Steps to Palindrome
You are given a string s
. In one step, you can change any character of s
to any other character. Your task is to determine the minimum number of steps required to transform s
into a palindrome.
A palindrome is a string that reads the same forwards and backwards. Formally, a string s
of length n is a palindrome if for all i in the range \(0 \le i < n\), we have:
[ s[i] = s[n-i-1] ]
For example, the string "abba" is already a palindrome and requires 0 steps, while "aab" requires 1 step (changing the last character from 'b' to 'a', or the first character from 'a' to 'b').
inputFormat
The input is read from standard input and consists of multiple test cases. The first line contains an integer T
, the number of test cases. Each of the following T
lines contains a non-empty string s
.
Example:
3 abba aab bba
outputFormat
For each test case, output a single integer on a new line representing the minimum number of steps required to make the string a palindrome.
Example:
0 1 1## sample
3
abba
aab
bba
0
1
1
</p>