private int offset(int i,int j){
  if (i < 0 || j > max || i > j) {
    throw new RuntimeException(String.format("Invalid span (%d,%d | %d)",i,j,max));
  }
  return i * (max + 1) - i * (i + 1) / 2 + j;
}

private int offset ( int i , int j ) { if ( i < 0 || j > max || i > j ) { throw new RuntimeException ( String . format ( "Invalid span (%d,%d | %d)" , i , j , max ) ) ; } return i * ( max + 1 ) - i * ( i + 1 ) / 2 + j ; }
this computes the offset into the one - dimensional array for a given span .
