Appzen may represent an audit chain as a linked list of event records. Given its pointer representation, determine whether following next references from the head eventually revisits a node.
Use Floyd's tortoise-and-hare algorithm. The linked list is encoded by an integer array next_indices, where node i points to next_indices[i]; -1 represents the end of the list. The head parameter is the starting node index, or -1 for an empty list.
Implement has_cycle(next_indices, head). Return True if traversal from head enters a cycle, and False otherwise. Assume every non-negative pointer is a valid index in next_indices.
def has_cycle(next_indices, head):