Determining the cardinality of sets defined by recursively following indexes
You are visiting every node to check their chain, but if they've already been visited by a previous chain they don't need to be checked again.

So you can have a single "visited" HashSet outside the main loop which can be used to check whether they have been visited in the outside loop and used to break the inside loop. 

Then in each of the outside loop iterations you can continue if you have previously visited.

Note also that you don't need to return and store the actual cycle, just the length.

public int solution(Integer[] A) {

     int arrayLength = A.Length;
     int maxsize = 0;
     int count = 0;
     Set&lt;Integer&gt; visited = new HashSet&lt;Integer&gt;();

     if(arrayLength &lt;= 0)
     return 0;

     for(int i = 0; i &lt; arrayLength; i++) {
       if(visited.contains(i))
            continue;

       int tempNum = A[i];
       count = 0;
       while(!visited.contains(tempNum)){
           visited.add(tempNum);
           tempNum = A[tempNum];
           count++;
       }

       if(count &gt; maxsize) { 
          maxsize = count;
       }
    }
     return maxsize;
 }