Wish | Phone screen | Relationships
2218

Suppose we have a series of people relationships that look something like this:

[
["Bart", "brother", "Lisa"],
["Bart", "son", "Homer"],
["Marge", "wife", "Homer"],
["Lisa", "daughter", "Homer"]
]

i.e. inner lists have len == 3 and are in form name1, relationship, name2

Given a series of relatipnships as a list of lists, and given 2 names, return all known "sequances" of relationships from name1 to name2.

Example:
Input: relationships =[["Bart", "brother", "Lisa"], ["Bart", "son", "Homer"], ["Marge", "wife", "Homer"],["Lisa", "daughter", "Homer"]], name1 = "Bart", name2 = "Homer"
Output: ["Bart son Homer", "Bart brother Lisa daughter Homer"]

Comments (5)