java solution dfs
\nclass Solution {\n    public int arrayNesting(int[] nums) {\n        int max = Integer.MIN_VALUE;\n        \n        for(int i=0; i<nums.length; i++){\n      
```\nclass Solution {\n    public int arrayNesting(int[] nums) {\n        int max = Integer.MIN_VALUE;\n        \n        for(int i=0; i<nums.length; i++){\n            if(nums[i]<0)\n                continue;\n            \n            max = Math.max(max, calculateNodes(nums, i));\n        }\n        \n        return max;\n    }\n    \n    public int calculateNodes(int[] arr, int start){\n        if(start<0 || start==arr.length || arr[start]<0){\n            return 0;\n        }\n        \n        int nextNodetoVisit = arr[start];\n        arr[start] = Integer.MIN_VALUE;\n        return 1 + calculateNodes(arr, nextNodetoVisit);\n    }\n    \n}\n```
[]