Simple cpp solution <<DFS
\n\n# Complexity\n- Time complexity: O(n*n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) 
\n\n# Complexity\n- Time complexity: O(n*n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\nprivate:\n// unordered_map<int,bool> visited; \nvector<bool> visited;\n    int dfs(int i, vector<int>& nums){\n        if(visited[i])\n        return 0;\n\n        visited[i]=true;\n        return 1+dfs(nums[i],nums);\n    }\npublic:\n    int arrayNesting(vector<int>& nums) {\n        int n=nums.size();\n        int ans=0;\n        for(int i=0;i<n;i++){\n            visited.resize(n,false);\n            ans=max(ans,dfs(i,nums));\n        }\n\n        return ans;\n    }\n};\n```
['Recursion', 'C++']