InterviewLegend

Parent-Child Graphs

Alex Chen28 min readUpdated 309 real interview reports

The prompt usually starts with a small diagram. Ten sits above 2, both 1 and 2 are parents of 3, 4 has children 5 and 8, and the family runs down to 6, 7 and 9. Behind the picture is a flat list of (parent, child) pairs, one per link, and every person is an integer id. Wayfair's first-round interview often uses this input, next to a block of design scenarios, and the coding part can be as short as 20 to 25 minutes.

The question changes from one interview to the next, but the input stays the same. One asks which individuals have no parents and which have exactly one. Another wants a Premium question, the one farthest up. A third asks for the closest ancestor with no parents of its own, and a fourth asks whether two nodes share any ancestor at all. They all read the same structure, so build it once and get it right.

The Wayfair angle
Wayfair's version is a graph drawn like a tree, so treat it as a graph. A child can have two parents, the data can hold several roots, and nothing gives you one node to start a recursion from, so the lowest-common-ancestor routine from binary-tree prep doesn't apply. Build a child-to-parents map in one pass, then climb it breadth-first, and that handles every part. Watch the ids too. In one sample 0 is a real person whose parent is 4, and a truthiness check like if parent drops them without any error.

WayfairPremium lesson · Coding round

The 3 Wayfair problems are below.

  1. A Premium questionCoding · Medium · Frequently asked
  2. A Premium questionCoding · Medium
  3. A Premium questionCoding · Easy

Each with hints, the follow-up and a tested solution.

Get the Wayfair questions

$49 a year · all 100 companies · cancel anytime

From 309 Wayfair reports, forum threads behind logins and write-ups in Chinese.

Had your Wayfair interview?Tell us what they asked. Reviewed before it goes in, never with your name.
Wayfair interview guide

Know what Wayfair asks before you walk in.

31 coding · 3 system design · 24 behavioral questions

Get Premium$49 a year · Cancel anytime
Or start freeNo card.

Get their questions first.

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.