
The first line contains an integer 'T', which denotes the number of test cases or queries to be run. Then, the 'T' test cases follow.
The first line of each test case contains two space-separated integers, 'N' and 'M, as described in the problem statement.
The second line of each test case contains 'N' space-separated integers denoting the elements of the first array 'NUMS1'.
The third line of each test case contains 'M' space-separated integers denoting the elements of the second array 'NUMS2'.
For more clarity, please refer to the sample inputs.
For each test case, print a single line containing “True” if there are such two elements, else print “False”.
The output for each test case will be printed in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= N, M <= 5000
-10 ^ 9 <= X <= 10 ^ 9
Where 'N' and 'M' denote the size of the arrays and 'X' is the value of elements of the arrays.
Time Limit: 1 sec.
The approach is to find the sum of both the arrays beforehand. For every pair of elements, check if, after swapping, the resultant sum of the first array is equal to the resulting sum of the second array.
The approach is to use hashing. Mark all the elements of the second array true. For every element of the first array, we know exactly which value will be required to make the resultant sums of arrays equal. If for a particular element in the first array, the corresponding value exists in the second array, return True.