#C10578. Minimum Removals for Alternating String
Minimum Removals for Alternating String
Minimum Removals for Alternating String
You are given a string s
consisting only of the characters 'a'
and 'b'
. Your task is to remove the minimum number of characters so that the resulting string has no two consecutive identical characters.
In other words, if the given string is of length n and the characters are denoted as s0, s1, ..., sn-1, you are required to remove the minimum number of characters such that for every valid index i (with 1 ≤ i < n), the condition
holds true.
Example:
- For
s = "aabb"
, the answer is2
since one optimal way is to remove two consecutive characters to get "ab". - For
s = "abab"
, the string already contains no consecutive identical characters, so the answer is0
.
inputFormat
The input is read from standard input. It consists of a single line containing the string s
which is composed only of the characters 'a' and 'b'.
outputFormat
Output to standard output a single integer representing the minimum number of characters that need to be removed so that no two consecutive characters are the same.
## sampleaabb
2