CLEAN & SHORT PYTHON, O(N) TIME, O(N) SPACE
If the number is not present in the global set, then calculate the respective set for that number,\n* Else just continue because that number will yeild an alrea
* If the number is not present in the global set, then calculate the respective set for that number,\n* Else just continue because that number will yeild an already visited set ( and that will not make any difference to the result).\n```\nclass Solution:\n    def arrayNesting(self, nums: List[int]) -> int:\n        res, l = 0, len(nums)\n        globalSet = set()\n        for k in range(l):\n            if k not in globalSet:\n                currLength, currSet, val = 0, set(), k\n                while True:\n                    if nums[val] in currSet: break\n                    currSet.add(nums[val])\n                    globalSet.add(nums[val])\n                    currLength, val = currLength + 1, nums[val]\n                res = max(res, currLength)        \n        return res\n```
['Python', 'Python3']