Given two arrays A and B respectively of size N and M, the task is to print the count of elements in the intersection (or common elements) of the two arrays.
For this question, the intersection of two arrays can be defined as the set containing distinct common elements between the two arrays.
Input: 5 3 89 24 75 11 23 89 2 4 Output: 1 Explanation: 89 is the only element in the intersection of two arrays.
Input: 6 5 1 2 3 4 5 6 3 4 5 6 7 Output: 4 Explanation: 3 4 5 and 6 are the elements in the intersection of two arrays.
The task is to complete the function NumberofElementsInIntersection() which takes 4 inputs ie- array a, array b, n which is the size of array a, m which is the size of array b. The function should return the count of the number of elements in the intersection.
Expected Time Complexity: O(N + M).
Expected Auxiliary Space: O(min(N,M)).
1 ≤ N, M ≤ 105
1 ≤ A[i], B[i] ≤ 105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes