Count substrings of a given string whose anagram is a palindrome | C # program for the above approach ; Function to get the count of subStrings whose anagrams are palindromic ; Store the answer ; Map to store the freq of masks ; Set frequency for mask 00. . .00 to 1 ; Store mask in x from 0 to i ; Update answer ; Update frequency ; Print the answer ; Driver Code ; Function Call
using System ; using System . Collections . Generic ; class GFG { static void countSubString ( String s ) { int answer = 0 ; Dictionary < int , int > m = new Dictionary < int , int > ( ) ; m . Add ( 0 , 1 ) ; int x = 0 ; for ( int j = 0 ; j < s . Length ; j ++ ) { x ^= 1 << ( s [ j ] - ' a ' ) ; answer += m . ContainsKey ( x ) ? m [ x ] : 0 ; for ( int i = 0 ; i < 26 ; ++ i ) { answer += m . ContainsKey ( x ^ ( 1 << i ) ) ? m [ x ^ ( 1 << i ) ] : 0 ; } if ( m . ContainsKey ( x ) ) m [ x ] = m [ x ] + 1 ; else m . Add ( x , 1 ) ; } Console . Write ( answer ) ; } public static void Main ( String [ ] args ) { String str = " abab " ; countSubString ( str ) ; } }