Linked list cycle start
Your task
A singly linked list is encoded as next_arr, where next_arr[i] is the index of the node that follows node i, or -1 if it is the tail. head is the starting node index (or -1 for an empty list). If the list contains a cycle, return the index of the node where the cycle begins; otherwise return -1. Solve in O(1) extra space.
Examples
cycle_entry(next_arr: list[int], head: int) -> intExample 1
Input
cycle_entry([1, 2, 3, 1], 0)Output
1