1/39
Learn

Redirect chains, the way the coding round asks

Intersection of Two Linked Lists is on Airbnb's LeetCode tag lists (2 sources), a write-up of a senior Airbnb onsite loop lists finding where two linked lists with cycles overlap (1 source), and a candidate was handed two lists that each may or may not loop (1 report). This lesson's practice problem is that shape, on a link service's redirect chains, in three levels:

  1. drop_hops(head, blocked) and reverse_chain(head): change one chain in place, on 20,000 hops, without recursion.
  2. first_shared(a, b): the first hop two chains share, comparing hops and not urls, in O(1) extra memory.
  3. loop_start(head), and first_shared(a, b) when either chain may loop.
CallReturns
drop_hops(a, {"track.example/1", "track.example/2"})the hop link.example/a, now pointing at track.example/9
reverse_chain of hops 1, 2 and 3hop 3, now pointing at hop 2
first_shared(a, b)the hop track.example/9, one object on both chains
loop_start of a chain that loops backthe loop's first hop

The lesson builds it from the pointers up: nodes and what they cost, pointer order, reversing, two speeds, cycles, where two lists meet, and doubly linked lists. 16 steps end with a small task in the editor.