if sum == n means this char will provide its greatest permutation as nth permutation
for ( int i = MAX_CHAR - 1 ; k < len && i >= 0 ; i -- ) if ( freq [ i ] ) { out [ k ++ ] = i + ' a ' ; freq [ i ++ ] -- ; }