question: 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 ; }
target:  This computes the offset into the one-dimensional array for a given span.