c++ easiest and concise code
class Solution {\npublic:\n\n    vectordp;\n    int dfs(map&mp,vector&vis,int str)\n    {\n        if(vis[str]==1)\n            return 0;\n        if(dp[str]!=-
class Solution {\npublic:\n\n    vector<int>dp;\n    int dfs(map<int,int>&mp,vector<int>&vis,int str)\n    {\n        if(vis[str]==1)\n            return 0;\n        if(dp[str]!=-1)\n        {\n            vis[str]=1;\n            return dp[str];\n        }\n        else\n        {\n            vis[str]=1;\n            return dp[str]=1+dfs(mp,vis,mp[str]);\n        }\n    }\n    int arrayNesting(vector<int>& nums) {\n        dp.resize(nums.size(),-1);\n        map<int,int>mp;\n        for(int i=0;i<nums.size();i++)\n            mp[i]=nums[i];\n        int n=nums.size();\n        int count=INT_MIN;\n        vector<int>vis(n,0);\n        for(int i=0;i<n;i++)\n        {\n            count=max(count,dfs(mp,vis,i));\n        }\n        return count;\n    }\n};
['C']