Sharing my Snap phone screen question.
I was asked Leetcode 2316. Count Unreachable Pairs of Nodes in an Undirected Graph - worded slightly differently as follows:
There are n individuals. You are given pairs of individuals that like each other [ai, bi]. Return the number of pairs of individuals that do not like each other.
Questions I asked:
Questions I should have asked:
Initially, I wondered if I should use dfs based connected components or do union find.
I ended up using dfs which returned the size of each connected component. With the sizes in a list, I had to do a pairwise multiplication avoiding repetitions to get the number of people who don't like each other.
I did everything else, but messed up the pairwise multiplication at the end. Got a reject.
Question to the community: What other questions should I have asked? How can I improve based on this interview experience?