Minimum cost to convert one given string to another using swap , insert or delete operations | Function to find the minimum cost to convert string a to b ; Stores the frequency of string a and b respectively ; Store the frequencies of characters in a ; Store the frequencies of characters in b ; Minimum cost to convert A to B ; Find the minimum cost ; Print the minimum cost ; Driver Code ; Function Call
function minimumCost ( a , b ) { var fre1 = Array ( 256 ) . fill ( 0 ) , fre2 = Array ( 256 ) . fill ( 0 ) ; a . split ( ' ' ) . forEach ( c => { fre1 [ c . charCodeAt ( 0 ) ] ++ ; } ) ; b . split ( ' ' ) . forEach ( c => { fre2 [ c . charCodeAt ( 0 ) ] ++ ; } ) ; var mincost = 0 ; for ( var i = 0 ; i < 256 ; i ++ ) { mincost += Math . abs ( fre1 [ i ] - fre2 [ i ] ) ; } document . write ( mincost ) ; } var A = " " , B = " " ; minimumCost ( A , B ) ;