Last character > S [ i ] and its count > 0
while ( res . length > 0 && res [ res . length - 1 ] . charCodeAt ( 0 ) > s [ i ] . charCodeAt ( 0 ) && cnt [ res [ res . length - 1 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] > 0 ) {