Loading...
Loading...
Loading...
A chain of jobs may loop back: the last node's next can point to an earlier node. Given the values and the position that the last node points back to (-1 means no loop), print the value stored in the first node of the loop, or NONE if there is no loop. Values can repeat, so find the node, not the value.
Example 1
Input
3 2 0 4 1
Output
2
Example 2
Input
1 2 -1
Output
NONE
Try the problem first. Open one hint at a time.
First find a meeting point with slow and fast pointers.
Then restart one pointer at the head and move both one step at a time.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor