Snap: Count pairs of people who are not connected through mutual liking
Problem. There are n people and a list of pairs [a, b] meaning a and b like each other. Return how many pairs of people do not like each other. In graph terms, liking spreads through connections, so the answer counts pairs of people that sit in different connected groups.
Clarifications the candidate got. The relationship is undirected, and some people may never show up in any pair (they form groups of one).
Clarifications the candidate wished they had asked. Exactly how the expected output is derived from an input, and the input format.
Approach discussed. Find group sizes with DFS or union-find, then combine the sizes so each cross-group pair is counted exactly once.
Outcome and lesson. Everything worked except the final counting step, which had a bug, and the candidate was rejected. Their takeaways: pin down the output definition early, and check the pair-counting arithmetic carefully (a running total of people seen so far avoids double counting). They also felt they spent too long asking permission between steps.
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.