#K3681. Minimum Deletions for Alternating Characters
Minimum Deletions for Alternating Characters
Minimum Deletions for Alternating Characters
Given a string s consisting solely of the characters 'a' and 'b', your task is to determine the minimum number of deletions required so that the resulting string is alternating. A string is called alternating if no two adjacent characters are the same.
You can express the required number of deletions mathematically as:
$$ D = \sum_{i=1}^{n-1} \mathbf{1}\{s_i = s_{i+1}\} $$
where \(s_i\) represents the i-th character of the string and \(\mathbf{1}\{\cdot\}\) is the indicator function, which is 1 if the condition inside is true and 0 otherwise.
inputFormat
The input is provided via stdin and consists of a single line containing a non-empty string s that is composed only of the characters 'a' and 'b'.
outputFormat
Output to stdout a single integer representing the minimum number of deletions required to make the string alternating.
## sampleaab
1