Count substrings of a given string whose anagram is a palindrome | Java program for the above approach ; Function to print count of subStrings whose anagrams are palindromic ; Stores the answer ; Iterate over the String ; Set the current character ; Parity update ; Print the final count ; Driver Code ; Function Call
class GFG { static void countSubString ( String s ) { int res = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int x = 0 ; for ( int j = i ; j < s . length ( ) ; j ++ ) { int temp = 1 << s . charAt ( j ) - ' a ' ; x ^= temp ; if ( ( x & ( x - 1 ) ) == 0 ) res ++ ; } } System . out . print ( res ) ; } public static void main ( String [ ] args ) { String str = " aaa " ; countSubString ( str ) ; } }