Your question is Detect a Linked List Loop. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
An Equifax security-review workflow is represented as a singly linked chain. Detect whether following the next reference from the starting node eventually revisits a node.
Implement has_cycle(next_indices, head). Use Floyd's tortoise-and-hare technique and require constant extra space.
next_indices is an array where index i represents a node.next_indices[i] is the index of the next node, or -1 if node i terminates the chain.head is the starting node index, or -1 for an empty chain.True if a cycle is reachable from head; otherwise return False.def has_cycle(next_indices, head):