Minimum substring flips required to convert a Binary String to another | Function to count the minimum number of reversals required to make the given binary strings s1 and s2 same ; Stores the minimum count of reversal of substrings required ; If the length of the strings are not the same then return - 1 ; Iterate over each character ; If s1 [ i ] is not equal to s2 [ i ] ; Iterate until s1 [ i ] != s2 [ i ] ; Increment answer by 1 ; Return the resultant count of reversal of substring required ; Driver Code ; Function Call
function canMakeSame ( s1 , s2 ) { var ans = 0 ; if ( s1 . length != s2 . length ) { return - 1 ; } var N = s1 . length ; for ( var i = 0 ; i < N ; i ++ ) { if ( s1 [ i ] != s2 [ i ] ) { while ( i < s1 . length && s1 [ i ] != s2 [ i ] ) { i ++ ; } ans ++ ; } } return ans ; } var S1 = " " ; var S2 = " " ; document . write ( canMakeSame ( S1 , S2 ) ) ;