## GUPTA MECHANICAL

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

## [Solution] Minimum number of Flips CodeChef Solution | CodeChef Problem Solution 2022

Chef has an array $A$ of length $N$ consisting of $1$ and $-1$ only.

In one operation, Chef can choose any index $i$ $\left(1\le i\le N\right)$ and multiply the element ${A}_{i}$ by $-1$.

Find the minimum number of operations required to make the sum of the array equal to $0$. Output -1 if the sum of the array cannot be made $0$.

### Input Format

• First line will contain $T$, number of test cases. Then the test cases follow.

• First line of each test case consists of a single integer $N$ denoting the length of the array.
• 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 to make the sum of the

array equal to $0$. Output -1 if it is not possible to make the sum equal to $0$.

### Constraints

• $1\le T\le 100$
• $2\le N\le 1000$