So I had given Wayfair interview around a month back. And I could not make past the first round :(.
First round had 4 System Design questions and 1 coding problem
Sytem Design questions were easy. I explained them in detail but it took 30 mins. So I had only 25 mins to solve the coding problem. The coding problem was given a tree like structure
Given a list of pairs of (parent,child)-> [{1,2}, {1,3}, {2,4}, {4,0}, {3,5}, {8, 6}, {6,7}, {6,9}]
Find the closest ancestor of the node. Ancestor is a node with no parents.
For example -> 1) given a node 0, ancestor is 1 (only 1 ancestor)
2) given a node 7 , ancestor is 8 (It was 2 ancestors 8 and 1 ). Closest one is 8.
So The solution that I proposed was to build a map of child and list of parents map<Integer, List(Integer)> then doing recursion we need to find out which ancestor has least number of children between the given node and themselves. But I could not complete the code in time. What is the solution according to you guys here. And is there a related leetcode problem ?



