Back to problems

Detect and Break a Linked-List Cycle

Algorithm · Amazon · Medium

Requirements Starting from the head of a singly linked list, determine whether any nodes form a loop. When a loop is present, remove it by assigning NULL to the problematic next link: specifically, the link on the cycle's final node that currently leads back to the cycle's first node. Preparation First build cycle-entry detection with Floyd's algorithm, then modify it so it can identify the node just before the entry and clear that node's next field. Practice stating the…

Checking your access…