Python solution. O(1) space.
python\ndef arrayNesting(self, nums: List[int]) -> int:\n        mx = 0\n        for i in range(len(nums)):\n            if nums[i] == -1: continue # continue i
```python\ndef arrayNesting(self, nums: List[int]) -> int:\n        mx = 0\n        for i in range(len(nums)):\n            if nums[i] == -1: continue # continue if we already met it\n            length = 0\n            while nums[i] != -1: # stop when we meet the same number twice\n                nums[i], i = -1, nums[i]\n                length += 1\n            if length > mx: mx = length\n        return mx\n```
['Python']