#C2444. Minimum Moves to Make All Characters Identical
Minimum Moves to Make All Characters Identical
Minimum Moves to Make All Characters Identical
Given a string s, determine the minimum number of moves required to make all characters in the string the same. In one move, you can change a contiguous block of identical characters into any other single character.
Mathematically, if the string is represented as \(s_1 s_2 \ldots s_n\), the answer is given by:
\[ \text{moves} = \sum_{i=2}^{n} \mathbf{1}_{\{s_i \neq s_{i-1}\}}, \]
where \(\mathbf{1}_{\{s_i \neq s_{i-1}\}}\) is 1 if \(s_i \neq s_{i-1}\) and 0 otherwise.
Example: For s = "abbcaa"
, the moves are 3 since the characters change from 'a' to 'b', 'b' to 'c', and 'c' to 'a'.
inputFormat
The input is provided via standard input (stdin) as a single line containing the string s. The string can be empty, in which case the output should be 0.
outputFormat
Output a single integer representing the minimum number of moves required to make all characters in the string identical. The output is written to standard output (stdout).
## sampleabbcaa
3