[Kotlin] Clean and Simple Solution
\nclass Solution {\n    fun arrayNesting(nums: IntArray): Int {\n        val grouped = BooleanArray(nums.size)\n        var maxGroupSize = 0\n        \n        
```\nclass Solution {\n    fun arrayNesting(nums: IntArray): Int {\n        val grouped = BooleanArray(nums.size)\n        var maxGroupSize = 0\n        \n        nums.forEachIndexed { index, num ->\n            if (!grouped[index]) {\n                grouped[index] = true\n                var currentGroupSize = 1\n                var nextIndex = num\n                while (!grouped[nextIndex]) {\n                    ++currentGroupSize\n                    grouped[nextIndex] = true\n                    nextIndex = nums[nextIndex]\n                }\n                maxGroupSize = maxOf(maxGroupSize, currentGroupSize)\n            }\n        }\n        \n        return maxGroupSize\n    }\n}\n```
[]