Solution
C++ []\nclass Solution {\npublic:\n    int arrayNesting(vector<int>& nums) {\n        ios_base::sync_with_stdio(false);\n        cin.tie(NULL);\n\n        int m
```C++ []\nclass Solution {\npublic:\n    int arrayNesting(vector<int>& nums) {\n        ios_base::sync_with_stdio(false);\n        cin.tie(NULL);\n\n        int maxLen = 1;\n        for (int i = 0; i < nums.size(); ++i) {\n            if (nums[i] == i) continue;\n            int currLen = 1;\n            while (nums[i] != i) {\n                int next_i = nums[i];\n                nums[i] = nums[next_i];\n                nums[next_i] = next_i;\n                currLen++;\n            }\n            maxLen = max(maxLen, currLen);\n        }\n        return maxLen;\n    }\n};\n```\n\n```Python3 []\nclass Solution:\n    def arrayNesting(self, nums: List[int]) -> int:\n        ans = 0\n        for x in nums:\n            if x == -1: continue\n            cnt = 0\n            while nums[x] != -1:\n                cnt += 1\n                nums[x], x = -1, nums[x]\n            ans = max(ans, cnt)\n                \n        return ans\n```\n\n```Java []\nclass Solution {\n    public int arrayNesting(int[] nums) {\n        int res = 0;\n        for (int i = 0; i < nums.length; i++) {\n            if (nums[i] != Integer.MAX_VALUE) {\n                int start = nums[i], count = 0;\n                while (nums[start] != Integer.MAX_VALUE) {\n                    int temp = start;\n                    start = nums[start];\n                    count++;\n                    nums[temp] = Integer.MAX_VALUE;\n                }\n                res = Math.max(res, count);\n            }\n        }\n        return res;\n    }\n}\n```\n
['C++', 'Java', 'Python3']