Store the occurrence of all characters in a hash_array
let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( hash_str1 [ str2 [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] > 0 ) hash_str1 [ str2 [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] -- ; else count ++ ; if ( count > k ) return false ; }