An array nextIndices describes a linked list whose head is node 0; each value is the next node's index, or -1 for null. If the list has a cycle, return the index of the node where the cycle begins. If there is no cycle, return -1.
Do not modify the list — treat nextIndices as read-only, the same encoding used by linked-list-cycle.
Input / output
nextIndices: int[]int, the index where the cycle begins, or -1-1 or a valid index into nextIndices-1 or eventually repeats an index (a genuine cycle)Can you solve it using O(1) extra space (Floyd's cycle-detection / tortoise-and-hare), without a visited-set?