133. Detect a Cycle
Build the list from n values, then read one more integer c.
If c is -1, leave the list as it is. Otherwise, make the last node point back at the
node at 0-based position c, creating a loop.
Print Yes if the list contains a cycle, or No if it does not.
You must not use extra memory proportional to the list — walking with a set of visited nodes is not the intended solution.
Constraints - `0 ≤ n ≤ 100000` - `-1 ≤ c < n` - `-1000000 ≤ value ≤ 1000000`
Input
The first line contains an integer n, the number of nodes.
The second line contains n space-separated integers — the node values from head to tail.
The starter code builds the list for you; work on the nodes, not the array.
The third line contains an integer j. If j is -1 the list stays straight; otherwise the last node is linked back to the node at 0-based position j.
Output
Print exactly one word: Yes or No.