![]() |
VOOZH | about |
Given two arrays, the task is find common elements of the two arrays. The input arrays may contain duplicates and our job is to find all common elements We are allowed to return elements in any order.
Input : a[] = {1, 2, 1, 3, 1}, b[] = {3, 1, 3, 4, 1}
Output : {1, 3, 1}
1 appears two times in both the input arrays.Input : a[] = {1, 1, 1}, b[] = {1, 1, 1, 1, 1}
Output : {1, 1, 1}
1 appears three times in both the input arrays.Input : a[] = {1, 2, 3}, b[] = {4, 5, 6}
Output : {}
Table of Content
1 1 3
1 1 3
We can do better if two arrays are sorted. Please refer Intersection of Two Sorted Arrays for details.