#K34757. Minimum Deletions to Avoid Adjacent Duplicates
Minimum Deletions to Avoid Adjacent Duplicates
Minimum Deletions to Avoid Adjacent Duplicates
Given a string s, your task is to determine the minimum number of deletions required such that no two adjacent characters are identical.
For example, if s is "aaa", you should remove 2 characters so that only one a remains. Similarly, if s is "aabbcc", you must remove one character from each pair of adjacent duplicates, thus resulting in 3 deletions.
This problem tests your understanding of string manipulation and basic greedy algorithm techniques.
Note: The deletion count is computed by simply scanning the string once and counting every occurrence where the current character is the same as the previous one.
inputFormat
The first line of the input contains an integer T, representing the number of test cases. Each of the next T lines contains a non-empty string s.
Input Format:
T s1 s2 ... sT
outputFormat
For each test case, output a single integer on a new line: the minimum number of deletions required so that no two adjacent characters in the string are identical.
Output Format:
result1 result2 ... resultT## sample
3
abcdef
aabbcc
aaa
0
3
2
</p>