I have a problem to find common elements in two arrays and that\'s of different size.
Take , Array A1
of size n
and Array A2
o
In Python, you would write set(A1).intersection(A2)
. This is the optimal O(n + m).
There's ambiguity in your question though. What's the result of A1=[0, 0], A2=[0, 0, 0]? There's reasonable interpretations of your question that give 1, 2, 3, or 6 results in the final array - which does your situation require?