Floyd's algorithm gets you to cycle detection pretty fast, most people know that part.
Use Floyd's cycle detection algorithm (tortoise and hare) to determine if a cycle exists and find the meeting point. Then, reset one pointer to the head and move both pointers one step at a time until they meet at the cycle entry. Finally, traverse to the last node of the cycle and set its next pointer to NULL.
Pro tip: After finding the cycle entry, to remove the cycle, you can either traverse from the entry to find the node whose next is the entry, or use a more efficient method: while finding the entry, keep track of the previous node. This shows you understand optimization even within O(n).
Initialize two pointers, slow and fast, at the head. Move slow one step and fast two steps at a time until they meet or fast reaches the end. If fast reaches the end, no cycle exists, return false.
If a cycle is detected, reset one pointer to the head and keep the other at the meeting point. Move both one step at a time until they meet; the meeting node is the start of the cycle.
Starting from the cycle entry, traverse the cycle until you reach the node whose next pointer points back to the entry. That node is the last node of the cycle.
Set the next pointer of the last node to NULL to break the cycle. Return true to indicate the cycle was found and removed.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.