Sum of minimum and the maximum difference between two given Strings | Function to find the sum of the minimum and the maximum difference between two given strings ; Variables to store the minimum difference and the maximum difference ; Iterate through the length of the string as both the given strings are of the same length ; For the maximum difference , we can replace " + " in both the strings with different char ; For the minimum difference , we can replace " + " in both the strings with the same char ; Driver code
function solve ( a , b ) { var l = a . length ; var min = 0 , max = 0 ; for ( var i = 0 ; i < l ; i ++ ) { if ( a [ i ] == ' ' b [ i ] == ' ' a [ i ] != b [ i ] ) max ++ ; if ( a [ i ] != ' ' && b [ i ] != ' ' && a [ i ] != b [ i ] ) min ++ ; } document . write ( min + max ) ; } var s1 = " " , s2 = " " ; solve ( s1 , s2 ) ;