#C8671. Minimum Deletions to Avoid Adjacent Duplicates
Minimum Deletions to Avoid Adjacent Duplicates
Minimum Deletions to Avoid Adjacent Duplicates
You are given a string s. Your task is to determine the minimum number of deletions required so that no two adjacent characters are the same. In other words, for any two consecutive characters in the resulting string, we must have:
\( s_i \neq s_{i+1} \)
This problem can be formalized as follows: Given a string \( s \) of length \( n \), find the minimum number of characters to delete so that for all \( 1 \leq i < n \), the condition \( s_i \neq s_{i+1} \) holds after deletions. For example, if \( s = \texttt{aabcc} \), deleting two characters (one of the two consecutive 'a's and one of the two consecutive 'c's) will yield a valid string.
Note: The input will be provided as a single string via stdin
, and your program should output the answer to stdout
.
inputFormat
The input consists of a single line containing the string s. The string is composed of lowercase English letters and may be empty.
Input is read from stdin
.
outputFormat
Output a single integer representing the minimum number of deletions required so that no two adjacent characters in the string are the same.
Output must be written to stdout
.
aabcc
2