areas is a list of names: the first name is a territory and the rest are its direct parts. Every territory belongs to at most one larger one, and a single territory contains all the others, directly or through other territories.
A territory counts as containing itself. Given two different names first and second, find the smallest territory that contains both and return its name.areas=[["Valley", "North", "South"], ["North", "Mill", "Farm"], ["South", "Port"], ["Farm", "Barn"]], first="Barn", second="Mill" → 'North'
Barn is inside Farm, which is inside North; Mill is inside North too. No smaller territory holds both.
areas=[["Valley", "North", "South"], ["North", "Mill", "Farm"], ["South", "Port"], ["Farm", "Barn"]], first="Port", second="Farm" → 'Valley'
They lie in different halves of the valley, so only Valley holds both.
areas=[["Island", "Cove", "Peak"], ["Cove", "Pier"]], first="Cove", second="Pier" → 'Cove'
A territory contains itself, so the answer is Cove.
first ≠ second, both appear on the mapareas=[["Valley", "North", "South"], ["North", "Mill", "Farm"], ["South", "Port"], ["Farm", "Barn"]], first="Barn", second="Mill"
'North'
Run checks the first 3 tests in your browser. Submit checks all 63 tests on the server, hidden ones included.