## GUPTA MECHANICAL

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

## Geometric Mean Inequality Solution | CodeChef Problem Solution 2022

You are given an array $A$ of length $N$ containing the elements $-1$ and $1$ only. Determine if it is possible to rearrange the array $A$ in such a way that ${A}_{i}$ is not the geometric mean of ${A}_{i-1}$ and ${A}_{i+1}$, for all $i$ such that $2\le i\le N-1$.

$Y$ is said to be the geometric mean of $X$ and $Z$ if ${Y}^{2}=X\cdot Z$.

Solution Click Below:-

### 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 Yes if it is possible to rearrange $A$ in such a way that ${A}_{i}$ is not the geometric mean of ${A}_{i-1}$ and ${A}_{i+1}$, where $2\le i\le N-1$. Otherwise output No.

You may print each character of Yes and No in uppercase or lowercase (for example, yesyEsYES will be considered identical).

### Constraints

• $1\le T\le 200$
• $3\le N\le 1000$
• ${A}_{i}\in \left\{-1,1\right\}$

### Sample Input 1

3
5
1 1 1 -1 -1
3
1 1 1
6
1 -1 -1 -1 -1 1


### Sample Output 1

Yes
No
Yes


### Explanation

Test case 1: We can rearrange the array $A$ to $\left[1,1,-1,-1,1\right]$. One can see that ${A}_{i}\ne {A}_{i-1}\cdot {A}_{i+1}$, for any $2\le i\le N-1$.

Test case 2: None of the rearrangements of $A$ satisy the given condition.