## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## [Solution] Remove and Add CodeChef Solution | CodeChef Problem Solution 2022

You are given an array $A$ of $N$ integers. You must perform some (possibly zero) operations to make the elements of $A$ distinct.

In one operation, you can either:

• Remove one element from the beginning of the array $A$ and append any positive integer to the end.
• Or remove one element from the end of the array $A$ and prepend any positive integer to the beginning.

Find the minimum number of operations required to make all the elements of the array distinct.

### Input Format

• The first line contains a single integer $T$ — the number of test cases. Then the test cases follow.
• The first line of each test case contains an integer $N$ — the size of the array $A$.

• The second line of each test case contains $N$ space-separated integers ${A}_{1},{A}_{2},\dots ,{A}_{N}$ denoting the array $A$.

### Output Format

For each test case, output the minimum number of operations required to make all the elements distinct.

### Constraints

• $1\le T\le {10}^{3}$
• $1\le N\le 2\cdot {10}^{5}$
• The sum of $N$ over all test cases does not exceed $2\cdot {10}^{5}$