C++ Solution
\nclass Solution \n{\n    public:\n    int arrayNesting(vector<int>& nums) \n    {\n        int ans = 0;\n        for(int i=0;i<nums.size();i++)\n        {\n   
```\nclass Solution \n{\n    public:\n    int arrayNesting(vector<int>& nums) \n    {\n        int ans = 0;\n        for(int i=0;i<nums.size();i++)\n        {\n            if(nums[i]!=-1)\n            {\n                int start = nums[i];\n                int cnt = 0;\n                while(nums[start]!=-1)\n                {\n                    int temp=start;\n                    start=nums[start];\n                    cnt++;\n                    nums[temp]=-1;\n                }\n                ans=max(ans,cnt);\n            }\n        }\n        return ans;\n    }\n};\n```
['C', 'C++']