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
function differentBitwiseOR ( s1 , s2 ) { let n = s1 . length ; let t00 = 0 , t10 = 0 , t01 = 0 , t11 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( s1 [ i ] == ' ' && s2 [ i ] == ' ' ) { t00 ++ ; } if ( s1 [ i ] == ' ' && s2 [ i ] == ' ' ) { t10 ++ ; } if ( s1 [ i ] == ' ' && s2 [ i ] == ' ' ) { t11 ++ ; } if ( s1 [ i ] == ' ' && s2 [ i ] == ' ' ) { t01 ++ ; } } let ans = t00 * t10 + t01 * t10 + t00 * t11 ; document . write ( ans ) ; } let S1 = " " ; let S2 = " " ; differentBitwiseOR ( S1 , S2 ) ;