Largest Crowd
A party has n guests numbered 0 to n - 1. friendships is a list of pairs [a, b] with a != b meaning guests a and b are friends; the same pair may appear more than once. A crowd is a largest possible group of guests in which any two members are friends or are linked through a chain of friends inside the group.
Return the number of guests in the largest crowd. A guest with no friends forms a crowd of one, so the answer is at least 1.
Example 1
n 6
friendships [[0,1],[1,2],[3,4]]
returns 3
Guests 0, 1 and 2 form one crowd of three; 3 and 4 form a crowd of two; 5 is alone.
Example 2
n 4
friendships []
returns 1
Nobody has a friend, so every crowd has one guest.
Constraints
1 <= n <= 500 <= len(friendships) <= 1000 <= a, b <= n - 1anda != b
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.