code: private static void createList( int data[], int k , int level , List<int[]> ret )
      {
          data[k] = level;
  
          if( level < data.length-1 ) {
              for( int i = 0; i < data.length; i++ ) {
                  if( data[i] == -1 ) {
                      createList(data,i,level+1,ret);
                  }
              }
          } else {
              int []copy = new int[data.length];
              System.arraycopy(data,0,copy,0,data.length);
              ret.add(copy);
          }
          data[k] = -1;
      }
docs: Internal function that uses recursion to create the list