C++ easy solution
For every index find the number of elements in the set by \'res\' variable and take the maximum as result. For identifying the reoccurring element an array \'ar
For every index find the number of elements in the set by \'res\' variable and take the maximum as result. For identifying the reoccurring element an array \'arr\' is taken to mark the visited element as 1.\n\n```\nclass Solution {\npublic:\n    int dfs(vector<int>&nums,int ind,int arr[],int res)\n    {\n        if(arr[ind]==1)\n            return res;\n        res++;\n        arr[ind]=1;\n        return dfs(nums,nums[ind],arr,res);\n    }\n    int arrayNesting(vector<int>& nums) {\n        \n        int arr[nums.size()],ans=0;\n        for(int i=0;i<nums.size();i++)\n            arr[i]=0;\n        for(int i=0;i<nums.size();i++)\n        {\n            int res=dfs(nums,i,arr,0);\n            ans=max(res,ans);\n        }\n        return ans;\n    }\n};\n```
['Array', 'Depth-First Search', 'C']