Number of substrings with each character occurring even times | Function to count substrings having even frequency of each character ; Stores the total count of substrings ; Traverse the range [ 0 , N ] : ; Traverse the range [ i + 1 , N ] ; Stores the substring over the range of indices [ i , len ] ; Stores the frequency of characters ; Count frequency of each character ; Traverse the dictionary ; If any of the keys have odd count ; Otherwise ; Return count ; Driver Code
function subString ( s , n ) { var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var len = i + 1 ; len <= n ; len ++ ) { var test_str = s . substring ( i , len ) ; var res = { } ; var temp = test_str . split ( " " ) ; for ( const keys of temp ) { res [ keys ] = ( res [ keys ] ? res [ keys ] : 0 ) + 1 ; } var flag = 0 ; for ( const [ key , value ] of Object . entries ( res ) ) { if ( res [ key ] % 2 != 0 ) { flag = 1 ; break ; } } if ( flag == 0 ) count += 1 ; } } return count ; } var S = " " ; var N = S . length ; document . write ( subString ( S , N ) ) ;