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:
drop_hops(head, blocked)andreverse_chain(head): change one chain in place, on 20,000 hops, without recursion.first_shared(a, b): the first hop two chains share, comparing hops and not urls, in O(1) extra memory.loop_start(head), andfirst_shared(a, b)when either chain may loop.
Call Returns drop_hops(a, {"track.example/1", "track.example/2"})the hop link.example/a, now pointing attrack.example/9reverse_chainof hops 1, 2 and 3hop 3, now pointing at hop 2 first_shared(a, b)the hop track.example/9, one object on both chainsloop_startof 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.