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!

Why don't you think of the efficient way.

Here are your sets A and B. Do these by hand and see if you can think of anything.

A = [0,83,71,39,9,34,77,20,86,9,82,45,88,44,34,38,24,61,48,3,96,66,

B = [17,85,78,41,85,56,9,12,83,100,59,66,56,86,66,82,98,92,14,43,96,69,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.