#C2043. Minimum Color Changes
Minimum Color Changes
Minimum Color Changes
Problem Description
You are given a sequence of colored lights. Your task is to determine the minimum number of color changes required to make the sequence as visually appealing as possible by minimizing the alternation of colors.
More formally, given a sequence \(a_1, a_2, \dots, a_N\), you need to compute the number of indices \(i\) (with \(2 \le i \le N\)) such that \(a_i \neq a_{i-1}\). In mathematical terms, the answer is \[ \sum_{i=2}^{N} I(a_i \neq a_{i-1}), \] where \(I(condition)\) is 1 if the condition is true and 0 otherwise.
For example:
- For the sequence [1, 3, 3, 2, 2], the answer is 2.
- For the sequence [3, 3, 3], the answer is 0.
inputFormat
The input begins with an integer \(T\) denoting the number of test cases. Each test case consists of two lines:
- The first line contains an integer \(N\), the number of lights.
- The second line contains \(N\) space-separated integers representing the colors of the lights.
outputFormat
For each test case, print a single integer on a new line representing the minimum number of color changes. This is computed as \(\sum_{i=2}^{N} I(a_i \neq a_{i-1})\).
## sample2
5
1 3 3 2 2
3
3 3 3
2
0
</p>