Make a string from another by deletion and rearrangement of characters | Javascript program to find if it is possible to make a string from characters present in other string . ; Returns true if it is possible to make s1 from characters present in s2 . ; Count occurrences of all characters present in s2 . . ; For every character , present in s1 , reduce its count if count is more than 0. ; Driver code
let MAX_CHAR = 256 ; function isPossible ( s1 , s2 ) { let count = new Array ( MAX_CHAR ) ; for ( let i = 0 ; i < count . length ; i ++ ) { count [ i ] = 0 ; } for ( let i = 0 ; i < s2 . length ; i ++ ) count [ s2 [ i ] . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i < s1 . length ; i ++ ) { if ( count [ s1 [ i ] . charCodeAt ( 0 ) ] == 0 ) return false ; count [ s1 [ i ] . charCodeAt ( 0 ) ] -- ; } return true ; } let s1 = " " , s2 = " " ; if ( isPossible ( s1 , s2 ) ) document . write ( " " ) ; else document . write ( " " ) ;