One Airbnb candidate reported this version (1 report), and it's the practice problem's last level. Find each list's loop with loop_start first, then sort out five cases:
Predict
One list ends in None, and the other loops. Can they share a node?
Case
First shared node
both end
the leveled walk from the checkpoint, ending at None
one ends, one loops
none: a list that ends can't reach a loop
both loop, same first loop node
the leveled walk again, with that node playing the part of None
both loop, b's first loop node is on a's loop
every loop node is shared, so you need a rule for which one comes first
both loop, b's first loop node isn't on a's loop
none: two different loops
To tell the last two apart, walk once around a's loop from its first node and stop when you're back. Either you pass b's first loop node or you don't.
The fourth row is the one to state precisely before you code it. Here a enters a loop of six nodes at node 1, and b enters it at node 4:
Both lists end in one loop of six nodes
a
x
→
y
→
1
→
2
→
3
→
4
→
5
→
0
→back to 1
b
z
→
4
→
5
→
0
→
1
→
2
→
3
→back to 4
a enters the loop at node 1, and b at node 4. Every loop node is shared.
Both lists reach every node of the loop, but each reaches the loop first at its own entry, so no node is first for both. A rule that settles it is to return the first node on a's walk that b also reaches. That's where a enters the loop, node 1, so swapping the arguments gives b's entry, node 4. Say the rule, and ask if they want another.
All five cases keep O(1) memory: two runs of loop_start, then one leveled walk or one lap of a loop.