Everyone Knows Everyone
A club has n members numbered 0 to n - 1. Each entry of links is a pair [a, b]: members a and b know each other. Knowing goes both ways, and the same two members may be listed more than once, in either order.
Return True if every two different members know each other, and False otherwise. A club with a single member has no pairs to check, so the answer is True.
Example 1
n 3
links [[0,1],[1,2],[2,0]]
returns true
All three pairs are there: 0 with 1, 1 with 2, and 0 with 2.
Example 2
n 3
links [[0,1],[1,2]]
returns false
Members 0 and 2 do not know each other.
Example 3
n 1
links []
returns true
One member, no pairs.
Constraints
1 <= n <= 80 <= len(links) <= 40- a pair names two different members
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Graphs problems
- Friends in CommonBeginner
- Is There a RoadBeginner
- Next DoorBeginner
- No HandshakeBeginner
- Who Points at MeBeginner
- Busiest NodeEasy
- Cable GroupsEasy
- Count the LakesEasy