If I have an array of numbers like [5, 2, 3, 2, 0, 2]
I want to count the number of times I can continuously index the array until we come to an index we already visited, like this:
A[0] = 5 A[5] = 2 A[2] = 3 A[3] = 2 stop here because we already indexed 2. So my problem is: without using additional data structure to store the previously visited indices, is there a way I can tell my program when to stop indexing?