Count substrings of a given string whose anagram is a palindrome | Function to prcount of subStrings whose anagrams are palindromic ; Stores the answer ; Iterate over the String ; Set the current character ; Parity update ; Print final count ; Driver Code ; Function Call
def countSubString ( s ) : NEW_LINE INDENT res = 0 ; NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT x = 0 ; NEW_LINE for j in range ( i , len ( s ) ) : NEW_LINE INDENT temp = 1 << ord ( s [ j ] ) - ord ( ' a ' ) ; NEW_LINE x ^= temp ; NEW_LINE if ( ( x & ( x - 1 ) ) == 0 ) : NEW_LINE INDENT res += 1 ; NEW_LINE DEDENT DEDENT DEDENT print ( res ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = " aaa " ; NEW_LINE countSubString ( str ) ; NEW_LINE DEDENT