#C1802. Minimum Removals to Avoid Three Consecutive Buildings
Minimum Removals to Avoid Three Consecutive Buildings
Minimum Removals to Avoid Three Consecutive Buildings
Given an array of building heights, determine the minimum number of removals needed so that no three consecutive buildings have the same height. In other words, you must remove as few buildings as possible to ensure that for every three consecutive buildings, at least one pair is of different height.
You can remove any building, and each removal counts as one operation. Mathematically, for any three consecutive indices \(i, i+1, i+2\), the following condition must hold:
\( H_i \neq H_{i+1} \text{ or } H_{i+1} \neq H_{i+2} \)
Your task is to compute the minimal number of removals for each test case.
inputFormat
The input is given via standard input (stdin) and has the following format:
- The first line contains a single integer \(T\) representing the number of test cases.
- For each test case:
- The first line contains an integer \(n\), the number of buildings.
- The second line contains \(n\) space-separated integers representing the building heights.
outputFormat
For each test case, output a single line on standard output (stdout) that contains the minimum number of removals required such that no three consecutive buildings have the same height.
## sample3
6
1 2 2 2 1 3
5
4 4 4 4 4
7
5 5 5 6 6 6 7
1
2
2
</p>