[C++/Python/Scala] Straight DFS
C++ Solution:-\n\nclass Solution {\n    \n    int solve(vector<int>&nums,int i,vector<bool>& vis)\n    {\n        int ans=1;\n        vis[i]=true;\n        if(!
**C++ Solution:-**\n```\nclass Solution {\n    \n    int solve(vector<int>&nums,int i,vector<bool>& vis)\n    {\n        int ans=1;\n        vis[i]=true;\n        if(!vis[nums[i]])\n            ans+=solve(nums,nums[i],vis);\n        return ans;    \n    }\n    \n    \npublic:\n    int arrayNesting(vector<int>& nums) {\n        int n=nums.size();\n        vector<bool>vis(n,false);\n        int maxi=1;\n        for(int i=0;i<n;i++)\n        {\n            if(!vis[i])\n                maxi=max(maxi,solve(nums,i,vis));\n        }\n        return maxi;\n    }\n};\n```\n\n**Python Solution:-**\n```\nclass Solution:\n    def arrayNesting(self, nums: List[int]) -> int:\n        vis=[False]*len(nums)\n        def solve(i):\n            ans=1\n            vis[i]=True\n            if vis[nums[i]]==False:\n                ans+=solve(nums[i])\n            return ans\n        maxi=1\n        for i in range(len(nums)):\n            if vis[i]==False:\n                maxi=max(maxi,solve(i))\n        return maxi   \n```\n\n**Scala Solution:-**\n```\nobject Solution {\n    def arrayNesting(nums: Array[Int]): Int = {\n        val n=nums.length\n        val vis=new Array[Boolean](n)\n        def solve(i:Int):Int={\n            var ans=1\n            vis(i)=true\n            if(!vis(nums(i)))\n            ans+=solve(nums(i))\n            ans\n        }\n        var maxi=1;\n        for(i <- 0 until n)\n        maxi=maxi max solve(i)\n        maxi\n    }\n}\n```\n\n*If you liked the Solution. Do UPVOTE it!!!!!!*
['Depth-First Search', 'C', 'Python', 'Scala']