C++ solution Easy and Efficient
\nclass Solution {\npublic:\n    int arrayNesting(vector<int>& nums) {  \n        vector<int> vis(nums.size(),0);\n        int ans=0;\n        for(int i=0;i<num
```\nclass Solution {\npublic:\n    int arrayNesting(vector<int>& nums) {  \n        vector<int> vis(nums.size(),0);\n        int ans=0;\n        for(int i=0;i<nums.size();i++){\n            int k=i,count=0;\n            while(!vis[k]){\n                vis[k]=1;\n                count++;\n                k=nums[k];\n            }\n            ans=max(ans,count);\n        }\n        return ans;\n    }\n};\n```
['C']