Given a string consisting of the letters , and , we can perform the following operation:
Find the shortest string obtainable through applying this operation repeatedly.
For example, given the string we can reduce it to a character string by replacing with and with : .
Complete the stringReduction function in the editor below. It must return an integer that denotes the length of the shortest string obtainable.
stringReduction has the following parameter:
- s: a string
The first line contains the number of test cases .
Each of the next lines contains a string to process.
For each test case, print the length of the resultant minimal string on a new line.
For the first case, there are two solutions: or .
For the second case, one optimal solution is: .
For the third case, no operations can be performed so the answer is .