Building HashMap to store frequencies of all characters .
let hm = new Map ( ) ; for ( let i = 0 ; i < temp . length ; i ++ ) { if ( hm . has ( temp [ i ] ) ) hm . set ( temp [ i ] , hm . get ( temp [ i ] ) + 1 ) ; else hm . set ( temp [ i ] , 1 ) ; }