I have a problem in which we are given 2 sets A and B and we have to find set C which contains elements common to A and B.The set A and B can contain duplicates and set C is expected to contain distinct elements(i.e no repetition of the same element) common to A and B.

As a solution to this, I thought that first all the duplicates in A and B can be removed and then set C can be formed by comparing each element of A and B.

Is there any other efficient way to solve the problem?

Just post your idea and I will do the coding. Thanks in advance!