Minimum replacements such that no palindromic substring of length exceeding 1 is present in the given string | Function to count the changes required such that no palindromic subof length exceeding 1 is present in the string ;  ; Stores the count ; Iterate over the string ; Palindromic Subof Length 2 ; Replace the next character ; Increment changes ; Palindromic Subof Length 3 ; Replace the next character ; Increment changes ; Driver Code
def maxChange ( str ) : NEW_LINE INDENT str = [ i for i in str ] NEW_LINE DEDENT / * Base Case * / NEW_LINE INDENT if ( len ( str ) <= 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT minChanges = 0 NEW_LINE for i in range ( len ( str ) - 1 ) : NEW_LINE INDENT if ( str [ i ] == str [ i + 1 ] ) : NEW_LINE INDENT str [ i + 1 ] = ' N ' NEW_LINE minChanges += 1 NEW_LINE DEDENT elif ( i > 0 and str [ i - 1 ] == str [ i + 1 ] ) : NEW_LINE INDENT str [ i + 1 ] = ' N ' NEW_LINE minChanges += 1 NEW_LINE DEDENT DEDENT return minChanges NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = " bbbbbbb " NEW_LINE print ( maxChange ( str ) ) NEW_LINE DEDENT