Sum of minimum and the maximum difference between two given Strings | Java 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
class GFG { static void solve ( char [ ] a , char [ ] 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 ++ ; } System . out . print ( min + max + "NEW_LINE"); } public static void main ( String [ ] args ) { String s1 = " a + c " , s2 = " + + b " ; solve ( s1 . toCharArray ( ) , s2 . toCharArray ( ) ) ; } }