# Adjacent Pairs Codechef Solution

### We Are Discuss About CODECHEF SOLUTION

Adjacent Pairs Codechef Solution

## Adjacent Pairs Codechef Solution

Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW

## Problem

Let’s call an array B_1, B_2, \ldots, B_M good, if B_i \neq B_{i+1} for any i with 1 \le i \le M-1.

You are given a good array of N positive integers A_1, A_2, A_3, \ldots, A_N.

You can perform the following operations on this array:

• Choose any index i (1 \leq i \leq N) and a number X (1 \leq X \leq 10^9). Then, set A_i to X. After this operation, the array has to remain good.

You want to perform several operations so that the resulting array will contain exactly two distinct values. Determine the smallest number of operations needed to achieve this goal.

### Input Format

• The first line of input contains the integer T, the number of test cases. The description of test cases follows.
• The first line of each test case contains a single integer N  the length of the array.
• The second line of each test case contains N integers A_1, A_2, \dots, A_N  elements of the array.

### Output Format

For each test case, output a single integer  the smallest number of operations needed to achieve an array in which there are exactly two distinct values.

### Constraints

• 1 \leq T \leq 10^5
• 2 \leq N \leq 2 \cdot 10^5
• 1 \leq A_i \leq N
• It’s guaranteed that A_i \neq A_{i+1} for 1 \le i \le N-1 (that is, the array is good).
• The sum of n over all test cases does not exceed 2 \cdot 10^5.

• Subtask 1 (20 points): The sum of N over all test cases does not exceed 100
• Subtask 2 (10 points): The sum of N over all test cases does not exceed 500
• Subtask 3 (25 points): The sum of N over all test cases does not exceed 4000
• Subtask 4 (45 points): No additional constraints

### Sample 1:

Input

Output

2
5
4 5 2 4 5
2
1 2
3
0


### Explanation:

In the first test case, one of the optimal sequences of operations is:

(4, 5, 2, 4, 5) \to (2, 5, 2, 4, 5) \to (2, 5, 2, 4, 2) \to (2, 5, 2, 5, 2).

In the second test case, the array already contains only two distinct values, so the answer is 0.

Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW

## Adjacent Pairs Codechef Solution

Yhaa You have done it but next? if YOU Want to Get Others Please Visit Here JOIN NOW

Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW