A utility function to get sum of array elements freq [ i ] to freq [ j ]
static int sum ( int [ ] freq , int i , int j ) { int s = 0 ; for ( int k = i ; k <= j ; k ++ ) { if ( k >= freq . Length ) continue ; s += freq [ k ] ; } return s ; }