#K44112. Minimum Removals to Make a Good String

    ID: 27460 Type: Default 1000ms 256MiB

Minimum Removals to Make a Good String

Minimum Removals to Make a Good String

You are given a string s. A string is defined as good if no two adjacent characters are the same. In other words, a string s of length \( n \) is good if for every index \( i \) with \( 1 \le i < n \), the condition \( s_i \neq s_{i+1} \) holds.

Your task is to calculate the minimum number of characters that must be removed from the string so that the resulting string is good. For example, for the string "abb", one removal is required because after removing one of the adjacent 'b's, the string becomes "ab" which is good.

Input/Output requirements:

  • Input: The input is given via standard input (stdin). The first line contains an integer \( T \) denoting the number of test cases. Each of the following \( T \) lines contains a string \( s \) whose goodness is to be checked.
  • Output: For each test case, output the minimum number of removals required on a separate line via standard output (stdout).

inputFormat

The first line of input contains an integer \( T \) (\( 1 \le T \le 10^4 \)) representing the number of test cases. Each of the following \( T \) lines contains a non-empty string \( s \) consisting of lowercase English letters. The total length of all strings does not exceed \( 10^5 \).

outputFormat

For each test case, output a single integer denoting the minimum number of removals required to turn the string into a good string (i.e., no two adjacent characters are the same).

## sample
3
abb
aaab
ababa
1

2 0

</p>