JavaScript DFS with cache Easy to understand
\nvar arrayNesting = function(nums) {\n    const visited = new Set();\n    const dfs = (num, len) => {\n        if(visited.has(num)) return len;\n        visite
```\nvar arrayNesting = function(nums) {\n    const visited = new Set();\n    const dfs = (num, len) => {\n        if(visited.has(num)) return len;\n        visited.add(num);\n        len++;\n        return dfs(nums[num], len);\n    }\n    return nums.reduce((len, curr) => visited.has(curr) ? len : Math.max(dfs(curr,  0), len), 0);\n};\n```
['Depth-First Search', 'JavaScript']