#C10011. Minimum Transformations to Avoid Adjacent Duplicates

    ID: 39170 Type: Default 1000ms 256MiB

Minimum Transformations to Avoid Adjacent Duplicates

Minimum Transformations to Avoid Adjacent Duplicates

You are given a string s consisting of lowercase English letters. Your task is to determine the minimum number of character transformations required so that no two adjacent characters in the string are the same.

For example, if s = "aab", you can transform the second 'a' to some other letter resulting in "abb" or "acb" (depending on the transformation) so that no two adjacent characters are identical. The minimal number of transformations for this case is 1.

Note: A transformation means replacing a character with any other lowercase English letter.

The formula for the minimum number of transformations can be defined as:

[ \text{transformations}(s) = \sum_{i=1}^{n-1} \mathbb{1}(s_i = s_{i+1}) ]

where \(\mathbb{1}(\cdot)\) is the indicator function that is 1 if the condition is true and 0 otherwise, and \(n\) is the length of the string.

inputFormat

The input consists of a single line containing a string s, which may be empty. The string contains only lowercase English letters.

Input Format Example:

aab

outputFormat

Output a single integer representing the minimum number of transformations required so that no two adjacent characters in the string are the same.

Output Format Example:

1
## sample
aab
1