Sum of minimum and the maximum difference between two given Strings | C ++ program to find the sum of the 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void solve ( string a , string b ) { int l = a . length ( ) ; int min = 0 , max = 0 ; for ( int 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 ++ ; } cout << min + max << endl ; } int main ( ) { string s1 = " a + c " , s2 = " + + b " ; solve ( s1 , s2 ) ; return 0 ; }