C++ | O(n) Logic | Without extra space | Clean code
```\nclass Solution {\npublic:\n    int arrayNesting(vector& arr) {\n        int i,n = arr.size();\n        int mx=0;\n        \n        for(i=0; i<n; i++){\n  
```\nclass Solution {\npublic:\n    int arrayNesting(vector<int>& arr) {\n        int i,n = arr.size();\n        int mx=0;\n        \n        for(i=0; i<n; i++){\n            if(arr[i] != -1){\n                int x = i;\n                int l = 0;\n\n                while(arr[x] != -1){\n                    l++;\n                    int y = arr[x];\n                    arr[x] = -1;\n                    x = y;                \n                }\n                mx = max(mx, l);\n            }\n        }\n                \n        return mx;\n    }\n};
['C', 'C++']