← Questions

Intersection of two linked lists that may have cycles

0
AirbnbCodingLast asked Jan 2026

Given the heads of two singly linked lists, each of which may or may not contain a cycle, decide whether they share a node and return the first shared node. Find where each list's cycle starts (Floyd's algorithm). If neither has a cycle, use the usual length-difference method; if only one does, they cannot meet; if both do, they share the cycle only if one cycle entry can be reached from the other.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding