Python3 solution | Explained with comments
\'\'\'\n\nclass Solution:\n    def arrayNesting(self, nums: List[int]) -> int:\n        # you can use set to mark the element where you\'ve been before but inst
\'\'\'\n```\nclass Solution:\n    def arrayNesting(self, nums: List[int]) -> int:\n        # you can use set to mark the element where you\'ve been before but instead of extra memory you can just give the value of -1 to every element you\'ve visited\n        # then you just check if the current element is different from -1, if so you have to iterate in order to create a new path \n        # mark with -1 since the all elements are positive \n\t\t#if you like it, please upvote! ^^\n        \n        count_max = 0\n        for i in range(len(nums)):\n            if nums[i] != -1: #if it\'s not visited \n                count = 0\n                j = i\n                while nums[j] != -1:\n                    t = j\n                    j = nums[j]\n                    count += 1\n                    nums[t] = -1 # marking\n                if count > count_max:\n                    count_max = count\n        return count_max\n    \n```\n\'\'\'
['Python', 'Python3']