
The first line contains ‘T’, denoting the number of test cases.
The first line of each test case contains two integers, ‘N’ denoting the number of houses.
The second line of each test case contains an array ‘color’ containing ‘N’ space-separated integers.
For each test case, print a single integer, denoting the minimum number of houses that need to be repainted.
You are not required to print the expected output. It has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 10^5
0 <= color[i] <= 1
Time Limit: 1 sec
If we closely look at the pattern of houses, we can see that the colours will have to be alternate with only the starting colour deciding all the other colours. Hence, the colours will be either [0, 1, 0, … ] or [1, 0, 1, …]. We will try making both the patterns and return the minimum value.
The steps are as follows: