A Panasonic connected-device component stores its processing path as a singly linked list. A faulty update may cause one node to point back to an earlier node, creating an infinite traversal cycle.
Given an array next_indices and a starting node index head, determine whether the linked list contains a cycle. If it does, return the index of the node where the cycle begins. Otherwise, return -1.
next_indices is a list of integers. Node i points to next_indices[i].-1 represents a null pointer.head is the index of the first node, or -1 for an empty list.-1 when no cycle exists.next_indices.def detect_cycle(next_indices, head):