#K96212. Transformed String Length
Transformed String Length
Transformed String Length
You are given a string S
. Perform the following transformation: Initialize \( left = 0 \) and \( right = n - 1 \) (where \( n \) is the length of S
). While \( left < right \) and the characters at positions left
and right
are the same, increment left
and decrement right
. The resulting length of the transformed string is defined as \( right - left + 1 \).
For example, if S = "abba"
, the matching characters from both ends remove the whole string resulting in a length of 0. Process multiple test cases accordingly.
inputFormat
The input begins with an integer T
(1 ≤ T ≤ 100) representing the number of test cases. Each of the following T
lines contains a string S
(1 ≤ |S| ≤ 105).
outputFormat
For each test case, output a single integer representing the length of the string after performing the transformation.
## sample3
abba
abcba
abcd
0
1
4
</p>