public static int[] cells(int[] start,int[] end){
  Arrays.sort(start);
  Arrays.sort(end);
  int overlap=0;
  int gaps=0;
  for (int i=0, j=0; j < end.length; ) {
    if (i < start.length && start[i] < end[j]) {
      overlap++;
      i++;
    }
 else {
      j++;
      overlap--;
    }
    if (overlap == 0) {
      gaps++;
    }
  }
  int[] cells=new int[gaps * 2];
  overlap=0;
  gaps=0;
  int previousOverlap=0;
  for (int i=0, j=0; j < end.length; ) {
    if (i < start.length && start[i] < end[j]) {
      overlap++;
      if (previousOverlap == 0) {
        cells[gaps++]=start[i];
      }
      i++;
    }
 else {
      overlap--;
      if (overlap == 0) {
        cells[gaps++]=end[j];
      }
      j++;
    }
    previousOverlap=overlap;
  }
  return cells;
}

public static int [ ] cells ( int [ ] start , int [ ] end ) { Arrays . sort ( start ) ; Arrays . sort ( end ) ; int overlap = 0 ; int gaps = 0 ; for ( int i = 0 , j = 0 ; j < end . length ; ) { if ( i < start . length && start [ i ] < end [ j ] ) { overlap ++ ; i ++ ; } else { j ++ ; overlap -- ; } if ( overlap == 0 ) { gaps ++ ; } } int [ ] cells = new int [ gaps * 2 ] ; overlap = 0 ; gaps = 0 ; int previousOverlap = 0 ; for ( int i = 0 , j = 0 ; j < end . length ; ) { if ( i < start . length && start [ i ] < end [ j ] ) { overlap ++ ; if ( previousOverlap == 0 ) { cells [ gaps ++ ] = start [ i ] ; } i ++ ; } else { overlap -- ; if ( overlap == 0 ) { cells [ gaps ++ ] = end [ j ] ; } j ++ ; } previousOverlap = overlap ; } return cells ; }
calculate the ranges for the cells
