Min flips of continuous characters to make all characters same in a string | To find min number of flips in binary string ; If last character is not equal to str [ i ] increase res ; To return min flips ; Driver program to check findFlips ( )
function findFlips ( str , n ) { var last = ' ' ; var res = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( last != str . charAt ( i ) ) res ++ ; last = str . charAt ( i ) ; } return parseInt ( res / 2 ) ; } var str = " " ; var n = str . length ; document . write ( findFlips ( str , n ) ) ;