Possibility of a word from a given set of characters | Javascript program to check if a query string is present is given set . ; Count occurrences of all characters in s . ; Check if number of occurrences of every character in q is less than or equal to that in s . ; driver program
let MAX_CHAR = 256 ; function isPresent ( s , q ) { let freq = new Array ( MAX_CHAR ) ; freq . fill ( 0 ) ; for ( let i = 0 ; i < s . length ; i ++ ) freq [ s [ i ] ] ++ ; for ( let i = 0 ; i < q . length ; i ++ ) { freq [ q [ i ] ] -- ; if ( freq [ q [ i ] ] < 0 ) return false ; } return true ; } let s = " " ; let q = " " ; if ( isPresent ( s , q ) ) document . write ( " " ) ; else document . write ( " " ) ;