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:
[
['America', 'NA' ,'SA'],
['NA', 'MXC, 'USA', 'CAN'],
['SA', 'Argentina', 'Brazil', 'Chile'],
['MXC', 'Oaxaca', 'Puebla'],
['USA', 'CA', 'WY, 'NY'],
['CAN', 'ON', 'QU', SAS']
]
Example 1:
Input: place1 = "CA", place2 = "Puebla"
Output: "NA"Example 2:
Input: place1 = "WY", place2 = "NY"
Output: "USA"Example 3:
Input: place1 = "Chile", place2 = "WY"
Output: "America"This is basically finding the lowest common ancestor of a N-ary tree.