public class Solution { public int ArrayNesting(int[] nums) { int maxsize = 0; for (int i = 0; i < nums.Length; i++) { int size = 0; for (int k = i; nums[k] >= 0; size++) { int ak = nums[k]; nums[k] = -1; // mark a[k] as visited; k = ak; } maxsize = Math.Max(maxsize, size); } return maxsize; } }