code: public int[][] getSets() {
          int n = 0;
          for (int i = 0; i < forest.length; i++) {
              if (forest[i] < 0) {
                  n++;
              }
          }
          int[][] sets = new int[n][];
          int currentSet = 0;
          for (int i = 0; i < forest.length; i++) {
              if (forest[i] < 0) {
                  int setSize = 1 - forest[i] - 1;
                  sets[currentSet] = new int[setSize];
                  int currentIndex = 0;
                  for (int element = 0; element < forest.length; element++) {
                      if (getRoot(element) == i) {
                          sets[currentSet][currentIndex] = element;
                          currentIndex++;
                      }
                  }
                  currentSet++;
              }
          }
          return sets;
      }
docs: Retrieve the sets as 2D-array of ints.
  
  @return the sets