Count the friend circles among n people given direct friendship pairs.
Unlock detailed company stats for this questionUpgrade
You are given a list of n people labeled 0 to n-1. Some are directly friends, given as pairs in friendships. A friend circle is a group of people who are directly or indirectly friends. Count the friend circles.
Example: n = 5, friendships = [[0, 1], [2, 3], [3, 4]]. Output: 2, for the circles {0,1} and {2,3,4}.
The interviewer asked for time and space complexity. Follow-up: count the redundant edges, meaning connections that can be removed without changing the number of friend circles.
Expect follow-ups like
- Count the redundant edges: connections that can be removed without affecting the number of friend circles.
Community answers
No answers contributed by the community yet.


