I found this interesting problem and couldn’t able to solve it.

Can you help me identify the category of this problem? so that I can practice similar questions.

so far my understanding is, we have to calculate the numbers of groups.

For example, Suppose pair of friends are

A B, D B, R G, T G

so there are two groups

first one is A B D, second is R T G.

so the answer is 1 because we can convert this into one group by just making one friendship between the first group and second group.

below is the problem statement.

Read about connected components in a graph and disjoint sets union.

1 Like

Thanks.

1 Like