1/38
Learn

Regions inside regions, the way the coding round asks

Smallest Common Region is on Airbnb's LeetCode tag lists (2 sources), an Airbnb candidate reported a tree whose every parent holds the sum of its children, with values that change (1 report), and two Netflix candidates describe their coding question as a depth-first search over a tree (2 reports). This lesson's practice problem is that shape, a travel site's regions, in three levels:

  1. RegionTree(lists) with top(), depth(region) and places_in(region): the tree from its lists, which come in any order.
  2. smallest_common(a, b): the smallest region that contains both.
  3. set_listings(region, count) and listings(region), where a read never walks the regions inside, on a chain of 50,000.
CallReturns
top(), with Japan's list first"Asia"
depth("Shibuya")4
places_in("Japan")8
smallest_common("Shinjuku", "Kyoto")"Japan"

The lesson builds it from trees up: recursion, a stack of your own, paths, depth-first search on graphs, and backtracking. 16 steps end with a small task in the editor.