


The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows
The first line of each test case contains a single integers ‘N’ denoting the length of the array.
The second line of each test case contains ‘N’ integers denoting the array elements.
For each test case print a single integer denoting the count of pairs with zero-sum.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 10^4
10^-9 <= arr[i] <= 10^9
Time limit: 1 sec
We can generate all pairs possible and check whether their sum is equal to zero.
To generate all the pairs: for each x in the range [0, N-2] iterate through all y in the range [x+1, N-1].
The steps are as follows :
Create a hash-map to store the count of the frequency of each array element. Now simply iterate on the created hash-map, if the current key is equal to x then search if -x exists in the hash-map or not, if it exists then add the frequency of x multiplied by the frequency of -x to the count. Notice that we are double counting things here, so remember to return count/2.
Remember to separately handle the border case when array element is equal to 0.
The steps are as follows :