#K3991. Minimize Changes to Avoid Adjacent Duplicate Flags
Minimize Changes to Avoid Adjacent Duplicate Flags
Minimize Changes to Avoid Adjacent Duplicate Flags
You are given a row of flags where each flag is represented by an integer denoting its color. However, if two adjacent flags have the same color, the arrangement is not acceptable. Your task is to determine the minimum number of flags that must be changed so that no two adjacent flags share the same color.
For example, if n = 6 and the flag colors are [1, 1, 2, 3, 3, 3], you only need to change 2 flags to ensure that adjacent flags have different colors.
Note: A change means you can change the flag's color to any integer that is different from its neighboring colors. The optimal strategy is to treat blocks of consecutive identical numbers and change ⌊L/2⌋ flags in any block of length L.
inputFormat
The input is given via standard input. The first line contains a single integer n (1 ≤ n ≤ 10^5) denoting the number of flags. The second line contains n space-separated integers, each representing the color of a flag.
outputFormat
Output a single integer (to standard output) representing the minimum number of changes required so that no two adjacent flags have the same color.## sample
6
1 1 2 3 3 3
2
</p>