Array Nesting || fast || Time and space complexity O(n), O(1) respectively
\nclass Solution {\npublic:\n    int cal_length(vector<int> &nums,int start)\n    {\n        if(start<0||start>=nums.size()||nums[start]<0)\n        return 0;\n
```\nclass Solution {\npublic:\n    int cal_length(vector<int> &nums,int start)\n    {\n        if(start<0||start>=nums.size()||nums[start]<0)\n        return 0;\n        int nextValue=nums[start];\n        nums[start]=-1;\n        return 1+cal_length(nums,nextValue);\n    }\n    int arrayNesting(vector<int>& nums) {\n    int n=nums.size();\n        if(n==0)\n        return 0;    \n    int maxi=INT_MIN;\n    for(int i=0;i<n;i++)\n    {\n        if(nums[i]<0)\n        continue;\n        maxi=max(maxi,cal_length(nums,nums[i]));\n    }  \n        return maxi;\n    }\n};\n```\n**Upvote if u like :)\nHappy coding**
[]