This function calculates number of unique characters using a associative array count [ ] . Returns true if no . of characters are less than required else returns false .
function isValid ( count , k ) { let val = 0 ; for ( let i = 0 ; i < MAX_CHARS ; i ++ ) { if ( count [ i ] > 0 ) { val ++ ; } }