simple c++ solution using visited array(extra space)
Plz upvote if you like -\n\n\tclass Solution {\n\tpublic:\n\t\tbool vis[100005];\n\t\tint arrayNesting(vector& nums) {\n\t\t\tint n = nums.size();\n\t\t\tint co
Plz upvote if you like -\n\n\tclass Solution {\n\tpublic:\n\t\tbool vis[100005];\n\t\tint arrayNesting(vector<int>& nums) {\n\t\t\tint n = nums.size();\n\t\t\tint count = 0;\n\t\t\tint ans = INT_MIN;\n\t\t\tmemset(vis,false,sizeof vis);\n\t\t\tfor(int i=0;i<n;i++)\n\t\t\t{\n\t\t\t\tcount = 0;\n\t\t\t\twhile(vis[nums[i]] == false)\n\t\t\t\t{\n\t\t\t\t\t\tvis[nums[i]] = true;\n\t\t\t\t\t\tnums[i]= nums[nums[i]]; // updating\n\t\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t\tans = max(ans,count);\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\t};
['C']