C++ || Easy approach
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:O(n^2)\n\n- Space complexity:O(n)\n\n# Code\n\nclass Solution {\npublic:\n    int array
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:$$O(n^2)$$\n\n- Space complexity:$$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int arrayNesting(vector<int>& nums) {\n        int ans=0;\n        vector<int>v(nums.size(), 0);\n        for(int i=0; i<nums.size(); i++){\n            int cnt=0, k=i;\n            while(!v[k]){\n                v[k]=1;\n                cnt++;\n                k=nums[k];\n            }\n            ans=max(ans, cnt);\n        }\n        return ans;\n    }\n};\n```
['Array', 'C++']