| Topic | Difficulty | Companies |
|---|---|---|
| Hash Table | MEDIUM | Google Facebook |
Given two integer arrays arr1[] and arr2[] of size m and n respectively, Write a program to find the intersection of these two arrays. The intersecting elements will be returned in the form of an integer array as an output.
Problem Note
Example 1
Input: arr1[] = [1, 2, 3, 4, 5], arr2[] = [5, 4, 3, 2, 1]
Output: [1, 2, 3, 4, 5]
Explanation: In the above example, all elements are similar in both the arrays. Hence, we get [1, 2, 3, 4, 5] as the output.
Example 2
Input: arr1[] = [1, 1, 3, 4, 5], arr2[] = [1, 1, 2, 3, 4, 5]
Output: [1, 3, 4, 5]
Explanation: In the above example, element 1 is repeated twice in both arrays but it is taken only once in the output. Element 2 is present in arr2 but not present in arr1, rest all elements are present in both the arrays. Hence, we get [1, 3, 4, 5] as the output.