#C2683. Minimum Deletions to Remove Consecutive Duplicates
Minimum Deletions to Remove Consecutive Duplicates
Minimum Deletions to Remove Consecutive Duplicates
You are given a binary string and your task is to remove the minimum number of characters so that no two consecutive characters are the same. In other words, after deleting the necessary characters, the resulting string should not contain any adjacent duplicate characters.
For example, if the string is 0001
, you can remove two of the zeros to obtain 01
which has no consecutive duplicates.
The solution involves scanning the string and counting the number of adjacent pairs of matching characters, which directly indicates the minimum number of deletions required.
inputFormat
The input is given via standard input (stdin) in the following format:
T S1 S2 ... ST
Here, the first line contains an integer T representing the number of test cases. Each of the next T lines contains a binary string S.
outputFormat
For each test case, output a single integer on a new line denoting the minimum number of deletions required so that no two consecutive characters in the string are the same. The output should be written to standard output (stdout).
## sample3
010101
0001
1110
0
2
2
</p>