Snap | Phone Screen | SWE
Anonymous User
665

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:

  • Is the graph directed or undirected? Answer was undirected.
  • Can you explain how the output is obtained for the given input. (as the question was vague).
  • Kept asking if I can proceed at intervals like when I suggested a possible solution and then when I had to code it up, or when I had to run it.
  • Will all 'n' individuals be in a pairing? Answer was no.

Questions I should have asked:

  • What is the input edge list? Array or list. I assumed list and kept going. Not that the type itself matters, but confirming inputs is necessary and not doing it does matter.

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?

Comments (4)