Minimum cost to make two strings same | Function to return the minimum cost to make the configuration of both the strings same ; Iterate and find the cost ; Find the minimum cost ; Driver Code
function findCost ( s1 , s2 , a , b , c , d , n ) { var cost = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( s1 [ i ] == s2 [ i ] ) continue ; else { if ( ( s1 [ i ] == ' ' && s2 [ i ] == ' ' ) || ( s2 [ i ] == ' ' && s1 [ i ] == ' ' ) ) cost += Math . min ( d , Math . min ( a , b + c ) ) ; else if ( ( s1 [ i ] == ' ' && s2 [ i ] == ' ' ) || ( s2 [ i ] == ' ' && s1 [ i ] == ' ' ) ) cost += Math . min ( d , Math . min ( b , a + c ) ) ; else if ( ( s1 [ i ] == ' ' && s2 [ i ] == ' ' ) || ( s2 [ i ] == ' ' && s1 [ i ] == ' ' ) ) cost += Math . min ( d , Math . min ( c , a + b ) ) ; } } return cost ; } var s1 = " " ; var s2 = " " ; var a = 2 , b = 3 , c = 4 , d = 10 ; var n = s1 . length ; document . write ( findCost ( s1 , s2 , a , b , c , d , n ) ) ;