


0 <= i,j,k,l < ‘N’
ARR1[i] + ARR2[j] + ARR3[k] + ARR4[l] = 0.
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains a single integer, 'N,’ denoting the number of elements in each array.
The next 4 lines of each test case have ‘N’ integers corresponding to the elements of 'ARR1', ‘ARR2’, ‘ARR3’, ‘ARR4’ respectively.
For each test case, return a single integer corresponding to the number of possible tuples.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 500
-100 <= 'ARR1'[i] , ARR2[i], ARR3[i] ,ARR4[i] <= 100
Time limit: 1 sec
In this approach, we will iterate over all possible tuples and check if the sum of 4 numbers is 0 or not. If they sum up, we will increment ‘AND'. Return the number of tuples in the end.
In this approach, First we will sort ARR4 so that we can apply binary search on that.We will try to form each possible triplet among the elements of ‘ARR1’ ’ARR2’ and ‘ARR3’. We will store the sum of these triplets in a variable ‘SUM’. Now using binary search we will try to find the number of occurrences of -1*’SUM’ using function count(‘ARR4’,’REQ’).We will update ‘ANS’ as ‘ANS’ + count(‘ARR4’,-1*’SUM’).
count(‘ARR’, ‘REQ’) will return the number of occurrences of ‘REQ’ in array ‘ARR’ using binary search.
In this approach, We will declare two hashmaps ‘HASHMAP1’ and ‘HASHMAP2’. ’HASHMAP1’ will store the frequency of the sum of all pairs of elements of ‘ARR1’ and ‘ARR2’.Similarly ’HASHMAP2’ will store the frequency of sum of all pairs of elements of ‘ARR3’ and ‘ARR4’. Now we will iterate through all elements of ‘HASHMAP1’ and search for the required element in ‘HASHMAP2’ and will update the ‘ANS’ accordingly.