You are given an array A of size N. You can perform the following operation on array A:
You need to make all the elements of the array equal to zero.
Task
Determine the minimum number of operations required to make all the elements of A equal to zero. Else, print -1 if it is not possible to do so.
Function description
Complete the function solve() provided in the editor. This function takes the following parameters and returns the required answer:
Input format
Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).
Output format
For each test case, print the output on a new line. Either the minimum number of operations required to make all the elements of A equal to zero or print -1 if it is impossible to do so.
Constraints
1≤T≤1000
1≤N≤105
−109≤Ai≤109 ∀ 1≤i≤N
∑Ni≤105 ∀ 1≤i≤T .
The first line contains the number of test cases, T = 2.
The first test case
Given
Approach
We can perform the following operations on A:
Hence, all the elements are equal to zero after 2 operations. Thus, the answer is 2.
The second test case
Given
Approach
It can be shown that it is not possible to reduce all the elements of A equal to zero simultaneously. Thus, the answer is -1.