Your question is Coding: Linked List Loop Detection. 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.
A Check Point security event pipeline stores events in a singly linked list. Implement the list construction and determine whether the list contains a loop, such as one caused by an incorrect event-linking operation.
The function receives a list of event identifiers and a loop position. It must build the linked list, connect the final node to the node at that position when applicable, and detect the loop using constant auxiliary space.
Implement has_loop(values, loop_index). values is a list of integers used to create one node per value. loop_index is the zero-based index of the node that the final node should reference, or -1 when the list should terminate at None. Return True if the constructed list contains a loop, otherwise return False.
Use a singly linked-list node with value and next fields. Do not traverse indefinitely, and do not use a set of visited nodes in the primary solution.
def has_loop(values, loop_index):