Airbnb | Phone screen | Lowest common territory that holds the given 2 places

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2019-01-14Added By Anonymous
Source: Link

Location: SF Bay Area


No Intro - Just straight to the problem


Problem: Find the lowest common territory that holds the given two places.


First column of each row is enclosing region, and following columns are all the regions within that row:

1[ 2['America', 'NA' ,'SA'], 3['NA', 'MXC, 'USA', 'CAN'], 4['SA', 'Argentina', 'Brazil', 'Chile'], 5['MXC', 'Oaxaca', 'Puebla'], 6['USA', 'CA', 'WY, 'NY'], 7['CAN', 'ON', 'QU', SAS'] 8]


Example 1:

1Input: place1 = "CA", place2 = "Puebla" 2Output: "NA"


Example 2:

1Input: place1 = "WY", place2 = "NY" 2Output: "USA"

Example 3:

1Input: place1 = "Chile", place2 = "WY" 2Output: "America"


This is basically finding the lowest common ancestor of a N-ary tree.

Comments