How would you detect a cycle in a linked list?
Implement detect_cycle(nodes, head_index), where nodes[i] stores the index of the next node and -1 represents null. Return True if traversal from head_index revisits a node, otherwise return False.
def detect_cycle(nodes, head_index):