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