Smallest Common Region
Updated
Problem statement
You are given a rooted hierarchy of named regions. Each row of regions starts with a parent region, followed by all of its direct child regions.
Given region1 and region2, return the smallest region that contains both. A region contains itself and every region in its descendant subtree.
The rows collectively describe one valid hierarchy. Every non-root region has exactly one parent, and every region name is unique within the hierarchy.
Function
findSmallestRegion(regions: String[][], region1: String, region2: String) → StringExamples
Example 1
regions = [["Earth","North America","South America"],["North America","United States","Canada"],["United States","New York","Boston"],["Canada","Ontario","Quebec"],["South America","Brazil"]]region1 = "Quebec"region2 = "New York"return = "North America"Quebec is under Canada, while New York is under United States. Their first shared ancestor is North America.
Example 2
regions = [["World","Asia","Europe"],["Asia","Japan","India"]]region1 = "Asia"region2 = "Japan"return = "Asia"A region contains itself, so Asia is the smallest region containing both Asia and its descendant Japan.
Constraints
1 <= regions.length <= 1000.- Each row contains one parent and at least one direct child.
- There are at most
1000distinct region names. - The rows describe one valid rooted hierarchy with unique names and no cycles.
region1andregion2both appear in the hierarchy.
More Airbnb Phone Screen questions
- Merge Event PreferencesPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Run-Length Encoding and DecodingPHONE SCREEN · Seen Nov 2026
- Read Across Sound TracksPHONE SCREEN · Seen Nov 2026
- Text JustificationPHONE SCREEN · Seen Nov 2026
- Decode and Store StringsPHONE SCREEN · Seen Oct 2026
- Print Sentences as TablePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Detonate Bombs with Chain ReactionsPHONE SCREEN · Seen Aug 2026
- Longest Chain BookingPHONE SCREEN · Seen Aug 2026
- Nested List Iterator with RemovePHONE SCREEN · Seen Jul 2026
- Parse Query StringPHONE SCREEN · Seen May 2026
Similar questions at other companies
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Lowest Common Ancestor in an N-ary TreeGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Lowest Common Ancestor in an N-ary TreeAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Tree Selection and VisibilityJane Street · PHONE SCREENJane Street interview questions
- Account Roles With Parent-User InheritanceStripe · PHONE SCREENStripe interview questions
- Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
- Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
- Build a File Tree from Streamed RecordsNextdoor · PHONE SCREENNextdoor interview questions
- Construct a Binary Tree from Preorder and InordereBay · PHONE SCREENeBay interview questions
Airbnb interview experiences
- Airbnb OA · November 2026
- Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
- Airbnb Intern Phone Interviews: 21 Experiences (Part 7 of 7)
- Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
- Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)
- Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)