python O(n) 98%, one pass with early exit, hashtable check
\nclass Solution:\n    def arrayNesting(self, nums: List[int]) -> int:\n        res, seen = 0, set()\n        for i in nums:\n            j, l = i, 0\n         
```\nclass Solution:\n    def arrayNesting(self, nums: List[int]) -> int:\n        res, seen = 0, set()\n        for i in nums:\n            j, l = i, 0\n            while j not in seen:\n                seen.add(j)\n                j = nums[j]\n                l += 1\n            if l > res:\n                res = l\n            if l > len(nums) - len(seen):  # early exit\n                break\n        return res\n```
[]