#C6132. Minimum Deletions to Avoid Repeating Consecutive Characters
Minimum Deletions to Avoid Repeating Consecutive Characters
Minimum Deletions to Avoid Repeating Consecutive Characters
Given a string (s), determine the minimum number of deletions required so that the remaining string does not contain any two consecutive identical characters. In other words, for a given string (s = s_0s_1\cdots s_{n-1}), you need to calculate: [ \text{minDeletions}(s) = \sum_{i=1}^{n-1} \delta(s_i, s_{i-1}) ] where (\delta(a, b) = \begin{cases} 1 & \text{if } a = b, \ 0 & \text{if } a \neq b. \end{cases}) The goal is to remove the minimum number of characters so that no two adjacent characters are the same.
inputFormat
The input consists of a single string (s) read from standard input. The string contains only lowercase English letters and its length is at least 1.
outputFormat
Output a single integer representing the minimum number of deletions required such that no two consecutive characters in the string are the same.## sample
aabbcc
3