


1. The output array should have the same ordering of elements as the original arrays.
2. Even if a particular element appears more than once in each of the three arrays, it should still be present only once in the output array.
3. If there are no common elements in the arrays, return an empty array.
Consider the three arrays A = [ 2, 3, 4, 7 ] , B = [ 0, 0, 3, 5 ] , C = [ 1, 3, 8, 9 ]
The output array should be [ 3 ] as 3 is the only element which is present in all the three arrays.
The first line of the input contains an integer 'T', denoting the number of test cases.
The first line of each test case contains three space-separated integers 'N', 'M' and 'K' denoting the number of elements in Array A, Array B and Array C respectively.
The second line of each test case contains 'N' space-separated integers denoting the elements of the array 'A'.
The third line of each test case contains 'M' space-separated integers denoting the elements of the array 'B'.
The fourth line of each test case contains 'K' space-separated integers denoting the elements of the array 'C'.
The only line of output of each test case should contain the elements that are common in all three arrays separated by space.
Print the output of each test case in a new line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N, M, K <= 30000
0 <= A[i] <= 10^9
0 <= B[i] <= 10^9
0 <= C[i] <= 10^9
Where 'A[i]', 'B[i]', 'C[i]' denotes the 'i'th' element of the arrays 'A', 'B' and 'C' respectively.
Time Limit: 1 sec
The idea is to iterate through one of the three arrays and for each element of the array iterate through the other two arrays and check whether that element is present in the other two arrays. If that element exists in the other two arrays, then we will add it to the output array provided it already does not exist in the output array. At the end we will return the output array.
Note that we can arbitrarily select any of the three arrays as the first array. We are selecting Array A as the first array.
The idea is to optimize the previous approach using Binary Search. This approach is quite similar to the previous approach. The major difference lies in the fact that in the previous approach to check whether any element P is present in Array ARR we were iterating through the whole array whereas in this approach we will use binary search to check whether any element P is present in Array ARR. This idea works because all the arrays are sorted. The advantage of using Binary search is that it optimizes the runtime of the algorithm that checks whether an element P is present in Array ARR from Linear Time Complexity to Logarithmic Time Complexity.
Let BinarySearch ( ARR, P ) be a function that returns True when element P exists in Array ARR. Otherwise it returns False.
The idea is to maintain three pointers one for each array. Let the pointer to Array A be p, pointer to Array B be q and pointer to Array C be r with all three of them initialized to 0. In each iteration we first get the element which is currently been pointed by first pointer i.e. A[p] and then we move the pointers to the other two arrays ahead while the element pointed by them is smaller than A[p]. Then we check whether the three elements i.e. A[p], B[q] and C[r] contain the same value.If yes, then we add that value to the output array provided it already does not exist in it and move the first pointer forward.
Element Count in Ranges
First Digit One
Minimize Maximum Adjacent Distance
Sorted Doubly Linked List to Balanced BST
Minimized Maximum of Products Distributed to Any Store