[Java/C++/Python] Straight Forward
Explanation:\nFor each element i in A,\nrepetly find A[i] until a visited element.\nUpdate res to the length of the path.\n\n\n# Complexity:\nEach element will 
# **Explanation**:\nFor each element `i` in A,\nrepetly find `A[i]` until a visited element.\nUpdate res to the length of the path.\n<br>\n\n# **Complexity**:\nEach element will be visited once,\nTime `O(N)`\nSpace `O(N)` (space can be `O(1)`)\n<br>\n\n**Java:**\n```java\n    public int arrayNesting(int[] A) {\n        int res = 0, n = A.length;\n        boolean[] seen = new boolean[n];\n        for (int i : A) {\n            int cnt = 0;\n            while (!seen[i]) {\n                seen[i] = true;\n                cnt++;\n                i = A[i];\n            }\n            res = Math.max(res, cnt);\n        }\n        return res;\n    }\n```\n\n**C++:**\n```cpp\n    int arrayNesting(vector<int>& A) {\n        int res = 0, n = A.size();\n        vector<bool> seen(n);\n        for (int i: A) {\n            int cnt = 0;\n            while (!seen[i]) {\n                seen[i] = true;\n                cnt++;\n                i = A[i];\n            }\n            res = max(res, cnt);\n        }\n        return res;\n    }\n```\n\n**Python:**\n```python\n    def arrayNesting(self, A):\n        seen, res = [0] * len(A), 0\n        for i in A:\n            cnt = 0\n            while not seen[i]:\n                seen[i], cnt, i = 1, cnt + 1, A[i]\n            res = max(res, cnt)\n        return res\n```\n
[]