[C++] Clean, Easy Solution; Simple Observation
Solution:\n\nApproach: \n Each element forms a cycle and gets visited only one time for that particular cycle(try to observe this using multiple examples) \n Th
**Solution:**\n\n**Approach:** \n* Each element forms a cycle and gets visited only one time for that particular cycle(try to observe this using multiple examples) \n* Thus, after observing this just create a visited array/map or mark the integer negative\n* If the element is already marked, this means we have already visited it and it is present in a unique cycle and continue your search for other elements\n* Find the maximum size out of all the unique cycles\n\n```\nclass Solution {\npublic:\n    int arrayNesting(vector<int>& nums) {\n        int n = nums.size();\n        int max_1 = INT_MIN;\n        for(int i = 0; i < n; i++){\n            int sz = 0;\n            int ind = i;\n            while(1){\n                if(nums[ind] == ind){\n                    sz = 1;\n                    break;\n                }\n                else if(nums[ind] < 0)\n                    break;\n                sz++;\n                nums[ind] *= -1;\n                ind = abs(nums[ind]);\n            }\n            max_1 = max(max_1, sz);\n        }\n        return max_1;\n    }\n};\n```
[]