Store the frequency of each character of S
let d = new Map ( ) ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( ! d . has ( s [ i ] ) ) d . set ( s [ i ] , 0 ) ; d . set ( s [ i ] , d . get ( s [ i ] ) + 1 ) ; }