Count substrings of a given string whose anagram is a palindrome | 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
function countSubstring ( s ) { var answer = 0 ; var m = new Map ( ) ; m . set ( 0 , 1 ) ; var x = 0 ; for ( var j = 0 ; j < s . length ; j ++ ) { x ^= 1 << ( s [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; answer += m . has ( x ) ? m . get ( x ) : 0 ; for ( var i = 0 ; i < 26 ; ++ i ) { answer += m . has ( x ^ ( 1 << i ) ) ? m . get ( x ^ ( 1 << i ) ) : 0 ; } if ( m . has ( x ) ) m . set ( x , m . get ( x ) + 1 ) else m . set ( x , 1 ) } document . write ( answer ) ; } var str = " " ; countSubstring ( str ) ;