Minimum characters that are to be inserted such that no three consecutive characters are same | Function to return the count of characters that are to be inserted in str such that no three consecutive characters are same ; To store the count of operations required ; A character needs to be inserted after str [ i + 1 ] ; Current three consecutive characters are not same ; Driver code
function getCount ( str , n ) { var cnt = 0 ; var i = 0 ; while ( i < n - 2 ) { if ( str [ i ] === str [ i + 1 ] && str [ i ] === str [ i + 2 ] ) { cnt ++ ; i = i + 2 ; } else { i ++ ; } } return cnt ; } var str = " " ; var n = str . length ; document . write ( getCount ( str , n ) ) ;