#C1911. Minimize Deletions to Make String Good
Minimize Deletions to Make String Good
Minimize Deletions to Make String Good
You are given a string s
. A string is considered good if no two adjacent characters are the same. Your task is to determine the minimum number of deletions required to make the string good.
For example, in the string aabcc
, you can remove one of the consecutive a
's and one of the consecutive c
's to obtain abc
, which is good. Therefore, the answer is 2
.
Note: The resulting string after deletions does not need to be a palindrome or sorted in any order; it only needs to have no two identical characters in a row.
Formal Description:
Given a string \( s \) of length \( n \), find the minimum number of deletions required such that for every index \( i \) (\( 1 \leq i < n \)), \( s_i \neq s_{i+1} \). That is, the string becomes good if no two adjacent characters are the same.
inputFormat
A single line containing the string ( s ). The string may include only lowercase English letters. It can be empty as well.
outputFormat
Print a single integer denoting the minimum number of deletions required to make the string good.## sample
aabcc
2