Python, Straightforward with Explanation
For every value 0 <= x < N, consider the set S_x = {x, A[x], A[A[x]], A[A[A[x]]],...}\nEvery node x belongs to some representative set S_i.  We'll repeatedly ta
For every value ```0 <= x < N```, consider the set ```S_x = {x, A[x], A[A[x]], A[A[A[x]]],...}```\nEvery node ```x``` belongs to some representative set ```S_i```.  We'll repeatedly take an unvisited node and visit all members of it's representative set.  We keep track of the size of this set ```bns = |S_i|``` and take a running max ```ans = max(ans, bns)```.\n\n```\ndef arrayNesting(self, A):\n    N = len(A)\n    ans = 0\n    seen = [False] * N\n    for x in xrange(N):\n    \tbns = 0\n    \twhile not seen[x]:\n            seen[x] = True\n            x = A[x]\n            bns += 1\n        ans = max(ans, bns)\n    return ans\n```
[]