This is actually DFS
\n\t/ ** \n\t * This is actually a DFS.  Use a visited map to keep track of visited node. If a \nnumber is visited before, then the set that starts at this numb
```\n\t/ ** \n\t * This is actually a DFS.  Use a visited map to keep track of visited node. If a \nnumber is visited before, then the set that starts at this number must be smaller then\n previous max. So we can safely skip this number. In total it's O(n) complexity.\n\t */\n\n\n\npublic int arrayNesting(int[] nums) {\n        int max = Integer.MIN_VALUE;\n        boolean[] visited = new boolean[nums.length];\n        for (int i = 0; i < nums.length; i++) {\n        \tif (visited[i]) \n        \t\tcontinue;\n        \tmax = Math.max(max, calcLength(nums, i, visited));\n        }\n        return max;\n    }\n\t\n\tprivate int calcLength(int[] nums, int start, boolean[] visited) {\n\t\tint i = start, count = 0;\n\t\twhile (count == 0 || i != start) {\n\t\t\tvisited[i] = true;\n\t\t\ti = nums[i];\n\t\t\tcount++;\n\t\t}\n\t\treturn count;\n\t}\n```
[]