text: Minimum flips to remove any consecutive 3 0 s or 1 s in given Binary string | Function to find the minimum number of flips to make all three pairs of consecutive characters different ; Stores resultant count of pairs ; Base Case ; Iterate over the range [ 0 , N - 2 ] ; If the consecutive 3 numbers are the same then increment the count and the counter ; Return the answer ; Driver Code
code: function minFlips ( str ) { let count = 0 ; if ( str . length <= 2 ) { return 0 ; } for ( let i = 0 ; i < str . length - 2 ; ) { if ( str [ i ] == str [ i + 1 ] && str [ i + 2 ] == str [ i + 1 ] ) { i = i + 3 ; count ++ ; } else { i ++ ; } } return count ; } let S = " " ; document . write ( minFlips ( S ) ) ;