Let’s assume ‘ARR1’ is [1,2,3,4,5] and ‘ARR2’ is [2,4,6,8]. Elements common to ‘ARR1’ and ‘ARR2’ are [2,4] as they occur in both ‘ARR1’ and ‘ARR2’. Therefore the number of elements common to ‘ARR1’ and ‘ARR2’ is 2. Union of ‘ARR1’ and ‘ARR2’ is [1,2,3,4,5,6,8]. Therefore the number of distinct elements in the union of ‘ARR1’ and ‘ARR2’ is 7. So, the answer will be 2 7.
1. ‘ARR1’ consists of distinct integers i.e no number occurs twice in array/list.
2. ‘ARR2’ consists of distinct integers i.e no number occurs twice in array/list.
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case contains two single space-separated integers ‘N' and ‘M’ representing the size of the array/list ‘ARR1’ and ‘ARR2’ respectively.
The second line of input of each test case contains ‘N’ single space-separated integers representing the array/list elements of ‘ARR1’.
The third line and the last line of input of each test contains ‘M’ single space-separated integers representing the array/list elements of ‘ARR2’.
For each test case, return the number of elements common to ‘ARR1’ and ‘ARR2’ and the number of distinct elements in the union of ‘ARR1’ and ‘ARR2’.
You do not need to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 1000
1 <= M <= 1000
1 <= ‘arr1[i]’ <= 10^5
1 <= ‘arr2[i]’ <= 10^5
Time Limit: 1sec
We will declare ‘INTERSECTION_SIZE = 0’ which stores the number of common elements in ‘arr’ and ‘brr’.
We will declare ‘INTERSECTION_SIZE = 0’ which stores the number of common elements in ‘ARR1’ and ‘ARR2’.
We will declare ‘INTERSECTION_SIZE = 0’ which stores the number of common elements in ‘ARR1’ and ‘ARR2’.
Merge Two Sorted Arrays Without Extra Space
Search In A Sorted 2D Matrix
Maximum GCD
Sort 0s, 1s, 2s
Fake Coin Problem