#C524. Minimum Removals for Alternating Characters
Minimum Removals for Alternating Characters
Minimum Removals for Alternating Characters
In this problem, you are given a string ( s ) consisting solely of the characters 'a' and 'b'. Your task is to find the minimum number of characters that must be removed from ( s ) so that the remaining characters form an alternating sequence. An alternating sequence is one where no two adjacent characters are the same, i.e. they follow the pattern 'abab...' or 'baba...'.
Example: If ( s = \texttt{aaab} ), you can remove two characters to obtain ( \texttt{ab} ), which is alternating.
Note: The requirement can be mathematically expressed as finding the minimum number of removals such that for every valid index ( i ) in the resulting string, ( s_i \neq s_{i+1} ).
inputFormat
The input consists of a single line containing the string ( s ) that is composed exclusively of the characters 'a' and 'b'.
outputFormat
Output a single integer representing the minimum number of removals required to make the string alternate.## sample
aaab
2