2 easy Python  🐍 solutions with comments
\nFirst solution O(n) time and O(n) space by using a seenIndex set\n\nclass Solution:\n    def arrayNesting(self, nums: List[int]) -> int:\n        seenInd=set(
\nFirst solution O(n) time and O(n) space by using a seenIndex set\n```\nclass Solution:\n    def arrayNesting(self, nums: List[int]) -> int:\n        seenInd=set()\n        start=0\n        res=1\n        \n        while start<len(nums):\n            if start in seenInd:\n                start+=1\n                continue\n            \n            count=1\n            nextInd=nums[start]\n            seenInd.add(start)\n            while nextInd not in seenInd:\n                count+=1\n                res=max(res,count)\n                seenInd.add(nextInd)\n                nextInd=nums[nextInd]\n        return res \n            \n```\n Second solution similar to solution1, but without using extra space, by marking seenIndecees by -1 so O(n0 time and O(1) space\n ```\n\n class Solution:\n    def arrayNesting(self, nums: List[int]) -> int:\n        start=0\n        res=1\n        \n        while start<len(nums):\n            if nums[start] == -1: #means that its seen before\n                start+=1\n                continue\n            \n            count=1 \n            nextInd=nums[start]\n            nums[start]=-1 #mark it as seen\n            while nums[nextInd] != -1: #i.e: not seen before\n                count+=1\n                res=max(res,count)\n                nums[nextInd], nextInd=-1,nums[nextInd]\n              \n        return res \n```
['Python', 'Python3']