Basic approach for beginners || Without using Graphs
Code\n\nclass Solution {\n    public int arrayNesting(int[] nums) {\n        int maxLength = 0;\n        \n        for (int i = 0; i < nums.length; i++) {\n    
# Code\n```\nclass Solution {\n    public int arrayNesting(int[] nums) {\n        int maxLength = 0;\n        \n        for (int i = 0; i < nums.length; i++) {\n            int length = 0;\n            int current = i;\n            \n            while (nums[current] != -1) {\n                int next = nums[current];\n                nums[current] = -1; // Marking as visited\n                length++;\n                current = next;\n            }\n            \n            maxLength = Math.max(maxLength, length);\n        }\n        \n        return maxLength;\n    \n    }\n    \n}\n```
['C', 'C++', 'Java']