 8

# Zero Pair Sum

Difficulty: MEDIUM Contributed By
Anshul Garg
Avg. time to solve
20 min
Success Rate
70%

Problem Statement

#### Specifically, find the count of all pairs ( i , j ) such that i < j and arr[i] + arr[j] = 0

##### Input Format :
``````The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows

The first line of each testcase contains a single integers ‘N’ denoting the length of the array.

The second line of each testcase contains ‘N’ integers denoting the array elements.
``````
##### Output Format :
``````For each test case print a single integer denoting the count of pairs with zero-sum.

Output for each test case will be printed in a separate line.
``````
##### Note :
``````You are not required to print anything; it has already been taken care of. Just implement the function.
``````
##### Constraints :
``````1 <= T <= 10
1 <= N <= 10^4
10^-9 <= arr[i] <= 10^9

Time limit: 1 sec
``````
##### Sample Input 1 :
``````2
4
1 -1 2 -2
5
1 2 3 4 5
``````
##### Sample Output 1 :
``````2
0
``````
##### Explanation Of Sample Output 1 :
``````For test case 1 :
Two pairs exist which have their sums equal to zero:
Pair formed by the first two elements has sum equal to zero, ie: 1 + (-1) = 0
Also, pair formed by the last two elements has sum qual to zero, ie: 2 + (-2) = 0

For test case 2 :
No pair can be formed with sum equal to zero.
``````
##### Sample Input 2 :
``````2
3
10 -5 -5
1
5
``````
##### Sample Output 2 :
``````0
0
``````   Console