Check if a Binary String can be converted to another by reversing substrings consisting of even number of 1 s | Function to check if string A can be transformed to string B by reversing substrings of A having even number of 1 s ; Store the size of string A ; Store the size of string B ; Store the count of 1 s in A and B ; Stores cntA for string A and cntB for string B ; Traverse the string A ; If current character is 1 ; Increment 1 s count ; Otherwise , update odd1A or even1A depending whether count1A is odd or even ; Traverse the string B ; If current character is 1 ; Increment 1 s count ; Otherwise , update odd1B or even1B depending whether count1B is odd or even ; If the condition is satisfied ; If true , print Yes ; Otherwise , print No ; Driver Code ; Function Call
function canTransformStrings ( A , B ) { let n1 = A . length ; let n2 = B . length ; let count1A = 0 , count1B = 0 ; let odd1A = 0 , odd1B = 0 ; let even1A = 0 , even1B = 0 ; for ( let i = 0 ; i < n1 ; i ++ ) { if ( A [ i ] == ' ' ) count1A ++ ; else { if ( ( count1A & 1 ) == 1 ) odd1A ++ ; else even1A ++ ; } } for ( let i = 0 ; i < n2 ; i ++ ) { if ( B [ i ] == ' ' ) count1B ++ ; else { if ( ( count1B & 1 ) == 1 ) odd1B ++ ; else even1B ++ ; } } if ( count1A == count1B && odd1A == odd1B && even1A == even1B ) { document . write ( " " ) ; } else document . write ( " " ) ; } let A = " " , B = " " ; canTransformStrings ( A , B ) ;