if sum > n fix that char as present char and update sum and required nth after fixing char at that position
if ( sum >= n ) { out += String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ; k ++ ; n -= ( sum - xsum ) ; break ; }