I got the acyclic case pretty fast, tail comparison or the length-difference two-pointer thing.
First, detect and locate the cycle entry point in each list using Floyd's cycle-finding algorithm. Then, if both lists have cycles, check if they share the same cycle by comparing the cycle entry nodes; if only one has a cycle, they cannot intersect; if neither has a cycle, find the intersection by aligning lengths or using two pointers.
Pro tip: Clarify with the interviewer whether the lists are allowed to have cycles and whether they share nodes by reference or value. Also, mention that if both have cycles, you can break the cycle temporarily to treat them as acyclic, but remember to restore it.
Use Floyd's tortoise and hare algorithm to determine if each list contains a cycle. If a cycle exists, find the entry node of the cycle.
If exactly one list has a cycle, they cannot intersect. If neither has a cycle, proceed to step 3. If both have cycles, proceed to step 4.
Compute the lengths of both lists, advance the pointer of the longer list by the length difference, then move both pointers in tandem until they meet or reach the end.
If both lists have cycles, check if they share the same cycle by comparing the cycle entry nodes. If the entry nodes are the same, they intersect; otherwise, traverse one cycle to see if the other's entry node is reachable.
If an intersection is found, return the first common node. Otherwise, return null to indicate no intersection.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.