Count substring of Binary string such that each character belongs to a palindrome of size greater than 1 | Function to find the substrings in binary string such that every character belongs to a palindrome ; Total substrings ; Loop to store the count of continuous characters in the given string ; Subtract non special strings from answer ; Driver Code ; Given string ; Function call
def countSubstrings ( s ) : NEW_LINE INDENT n = len ( s ) NEW_LINE answer = ( n * ( n - 1 ) ) // 2 NEW_LINE cnt = 1 NEW_LINE v = [ ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if ( s [ i ] == s [ i - 1 ] ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT else : NEW_LINE INDENT v . append ( cnt ) NEW_LINE cnt = 1 NEW_LINE DEDENT DEDENT if ( cnt > 0 ) : NEW_LINE INDENT v . append ( cnt ) NEW_LINE DEDENT for i in range ( len ( v ) - 1 ) : NEW_LINE INDENT answer -= ( v [ i ] + v [ i + 1 ] - 1 ) NEW_LINE DEDENT return answer NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s = "00111" NEW_LINE print ( countSubstrings ( s ) ) NEW_LINE DEDENT