Minimum number of flipping adjacent bits required to make given Binary Strings equal | Function to find the minimum number of inversions required . ; Initializing the answer ; Iterate over the range ; If s1 [ i ] != s2 [ i ] , then inverse the characters at i snd ( i + 1 ) positions in s1 . ; Adding 1 to counter if characters are not same ; Driver Code
function find_Min_Inversion ( n , s1 , s2 ) { let count = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( s1 [ i ] != s2 [ i ] ) { if ( s1 [ i ] = ' ' ) { s1 [ i ] = ' ' ; } else { s1 [ i ] = ' ' ; } if ( s1 [ i + 1 ] = ' ' ) { s1 [ i + 1 ] = ' ' ; } else { s1 [ i + 1 ] = ' ' ; } count ++ ; } } if ( s1 != s2 ) { return count ; } return - 1 ; } let n = 4 ; let s1 = " " ; let s2 = " " ; document . write ( find_Min_Inversion ( n , s1 , s2 ) ) ;