python | Simple DFS based approach | Notes | not very optimized though
\n/*\nwe can solve this problem using simple dfs based approach\nhave a visited set that keep tracks of indices that are already visited\nstart with index 0 and
```\n/*\nwe can solve this problem using simple dfs based approach\nhave a visited set that keep tracks of indices that are already visited\nstart with index 0 and recursively reach all the indexes possible until it reaches \nan index which was previously tracked. check the lenght of the current set,\nif it\'s greater than max length so far, update the answer\nRepeat the above step unless all the indexes are marked as visited\n*/\n```\n```\nclass Solution:\n    def arrayNesting(self, nums: List[int]) -> int:\n        max_len = 0\n        visited = set()\n        def dfs(nums, index, dfs_visited):\n            if index in dfs_visited:\n                return len(dfs_visited)\n            \n            # add the index to dfs_visited and visited\n            visited.add(index)\n            dfs_visited.add(index)\n            return dfs(nums, nums[index], dfs_visited)\n            \n        for i in range(len(nums)):\n            if i not in visited:\n                max_len = max(max_len, dfs(nums, i, set()))\n        return max_len\n```
['Depth-First Search', 'Python']