Java 1ms faster than 100% with explanation
\nclass Solution {\n    public int arrayNesting(int[] nums) {\n        int n=nums.length;\n        int count=0,max_c=Integer.MIN_VALUE;\n      //changed the val
```\nclass Solution {\n    public int arrayNesting(int[] nums) {\n        int n=nums.length;\n        int count=0,max_c=Integer.MIN_VALUE;\n      //changed the value at nums[i] to -(i+1) to keep track of elements visited\n\t  for(int i=0;i<n;i++){\n        if(nums[i]>=0){ // if nums[i]>=0 means the element is not visited\n          int indx=nums[i],val=-1*(i+1); \n     //if the duplicate element occur it will form a cycle i.e starting pt and ending pt will be equal\n\t\t while(indx!=i){ \n            int tmp=nums[indx];\n            nums[indx]=val;\n            val=-1*(indx+1);\n            indx=tmp;\n            count++;// count keeps track of no of elements in the cycle\n          }\n          nums[indx]=val;\n          count++; \n        }\n\t\t//max_c keep track of max value of count for each element in array\n        max_c=Math.max(max_c,count); \n        count=0;\n      }\n        return max_c;\n    }\n}\n```
['Java']