#K94362. Minimum Changes to Avoid Consecutive Same Color Blocks
Minimum Changes to Avoid Consecutive Same Color Blocks
Minimum Changes to Avoid Consecutive Same Color Blocks
You are given a sequence of blocks painted in one of the three colors: 'R', 'G', and 'B'. The goal is to modify the sequence by making the minimum number of changes so that no two consecutive blocks share the same color.
Formally, given an integer \( n \) and a string \( s \) of length \( n \) where each character is one of \( \{R, G, B\} \), determine the minimum number of changes required such that for all \( 1 \leq i < n \), \( s_i \neq s_{i+1} \).
A change means replacing the color of a block with any of the two other available colors. It is not required to output the modified sequence but only the count of changes needed.
inputFormat
The input consists of two lines:
- The first line contains a single integer \( n \) (\( 1 \leq n \leq 10^5 \)), representing the number of blocks.
- The second line contains a string of length \( n \). Each character of the string is 'R', 'G', or 'B', representing the color of a block.
outputFormat
Output a single integer representing the minimum number of changes required such that no two consecutive blocks have the same color.
## sample5
RRGBB
2