StraighForward DFS Clean code
Intuition:\nThis is actually dfs. Start from each element and check for cycle (for that change its value to -1). if cycle found , break and update the maximum a
**Intuition:**\nThis is actually dfs. Start from each element and check for cycle (for that change its value to -1). if cycle found , break and update the maximum ans.\n**Code:**\n```\nclass Solution {\npublic:\n    int arrayNesting(vector<int>& nums) {\n        \n        int ans=INT_MIN;\n        int n=nums.size();\n        for(int i=0;i<n;i++)\n        {\n            int k=i;\n            int sz=0;\n            while(nums[k]>=0)\n            {\n                sz++;\n                int next=nums[k];\n                nums[k]=-1;\n                k=next;\n                \n            }\n            ans=max(ans,sz);\n            \n            \n        }\n        return ans;\n        \n    }\n};\n```
['Depth-First Search']