Count different Bitwise OR values of equal length strings S1 and S2 by swapping exactly one pair of characters from the first string | Function to find the number of ways to obtain different Bitwise OR ; Stores the count of pairs t00 , t10 , t01 , t11 ; Traverse the characters of the string S1 and S2 ; Count the pair ( 0 , 0 ) ; Count the pair ( 1 , 0 ) ; Count the pair ( 1 , 1 ) ; Count the pair ( 0 , 1 ) ; Number of ways to calculate the different bitwise OR ; Print the result ; Driver Code
def differentBitwiseOR ( s1 , s2 ) : NEW_LINE INDENT n = len ( s1 ) NEW_LINE t00 = 0 NEW_LINE t10 = 0 NEW_LINE t01 = 0 NEW_LINE t11 = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( s1 [ i ] == '0' and s2 [ i ] == '0' ) : NEW_LINE INDENT t00 += 1 NEW_LINE DEDENT if ( s1 [ i ] == '1' and s2 [ i ] == '0' ) : NEW_LINE INDENT t10 += 1 NEW_LINE DEDENT if ( s1 [ i ] == '1' and s2 [ i ] == '1' ) : NEW_LINE INDENT t11 += 1 NEW_LINE DEDENT if ( s1 [ i ] == '0' and s2 [ i ] == '1' ) : NEW_LINE INDENT t01 += 1 NEW_LINE DEDENT DEDENT ans = t00 * t10 + t01 * t10 + t00 * t11 NEW_LINE print ( ans ) NEW_LINE DEDENT S1 = "01001" NEW_LINE S2 = "11011" NEW_LINE differentBitwiseOR ( S1 , S2 ) NEW_LINE