C++
\nint arrayNesting(vector<int>& a) {\n        int n = a.size(), ans = INT_MIN;\n        vector<int> v(n,0);\n        for(int i: a) {\n            int count = 0;
```\nint arrayNesting(vector<int>& a) {\n        int n = a.size(), ans = INT_MIN;\n        vector<int> v(n,0);\n        for(int i: a) {\n            int count = 0;\n            while(!v[i]) {\n               v[i] = true;\n               i = a[i];\n               count++;\n            }\n            ans = max(ans, count);\n        }\n        return ans;\n}\n```
[]