C++ || DFS solution
\tclass Solution {\n\tpublic:\n\t\tint dfs(vector &nums,vector &vis,int idx){\n\n\t\t\tif(vis[idx] == false){\n\t\t\t\tvis[idx] = true;\n\t\t\t\treturn 1 + dfs(
\tclass Solution {\n\tpublic:\n\t\tint dfs(vector<int> &nums,vector<bool> &vis,int idx){\n\n\t\t\tif(vis[idx] == false){\n\t\t\t\tvis[idx] = true;\n\t\t\t\treturn 1 + dfs(nums,vis,nums[idx]);\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\n\t\tint arrayNesting(vector<int>& nums) {\n\t\t\tint n = nums.size();\n\t\t\tvector<bool> vis(n,false);\n\t\t\tint ans = 0;\n\t\t\tint mx = INT_MIN;\n\t\t\tfor(int i=0;i<n;i++){\n\t\t\t\tif(vis[i] == false){\n\t\t\t\t   mx = max(mx,dfs(nums,vis,i));\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn mx;\n\t\t}\n\t};
[]