Relative Distance design choices

What is this exercise trying to achieve?

Like I said here, I wrote a solution in JS that does "parent = … find … " meaning find the first node. As I was about to run the tests I thought ‘Wait, I forgot the other parent’ and expected to hit a failing test - but no, all the tests passed.

So I looked into the dataset more, and realized that all the nodes (people) have a single parent and at most two children, which makes for a boring graph. The instructions say " a child can have one or two parents. ", but all the test data trees have a single parent.

Most of the tree(s) looks like a straight line A -> B -> C. From one of the tests: Fabio -> Sven -> Farah -> Tariq (-> Liam) until we hit the first fork, Liam. What’s the benefit of this?

Isaac (in the other topic) asked for interesting cases for two parents.


Well, suppose the input is

"Grandpa Joe" : ["Mr. Buckett"],
"Mrs. Buckett": ["Charlie"],
"Mr. Buckett": ["Charlie"]

With my current solution, distance("Charlie", "Grandpa Joe") will fail (return -1) and report that Charlie isn’t related to his grandad because it searches for the single parent and finds Mrs. Buckett first (who is not a descendant of grandpa Joe) and ignores Mr. Buckett (who is).

Now, of course in the current data there is no situation like this one.


Speaking of in-laws… If we decide that spouses aren’t related to one another* by marriage/co-parenting, and, adding to the previous example, Charlie has a child with Charlotte

"Charlote": ["Jr"],
"Charlie": ["Jr"]

Mr. Buckett should not be related to Charlotte, but a solution that iteratively adds children and parents to close family - a.k.a. distance 1 - would fail, reporting a distance of 3.

* There’s a saying/joke where I’m from “What do I care about <spouse>? He/she’s not my relative.” It’s a wordplay on the meaning of being related/family. :smile: