Count of Substrings with at least K pairwise Distinct Characters having same Frequency | Function to find the subString with K pairwise distinct characters and with same frequency ; Stores the occurrence of each character in the subString ; Length of the String ; Iterate over the String ; Set all values at each index to zero ; Stores the count of unique characters ; Moving the subString ending at j ; Calculate the index of character in frequency array ; Increment the frequency ; Update the maximum index ; Check for both the conditions ; Return the answer ; Driver Code ; Function call
function no_of_subString ( s , N ) { var fre = Array . from ( { length : 26 } , ( _ , i ) => 0 ) ; var str_len ; str_len = parseInt ( s . length ) ; var count = 0 ; for ( i = 0 ; i < str_len ; i ++ ) { fre = Array ( 26 ) . fill ( 0 ) ; var max_index = 0 ; var dist = 0 ; for ( j = i ; j < str_len ; j ++ ) { var x = s . charAt ( j ) . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; if ( fre [ x ] == 0 ) dist ++ ; fre [ x ] ++ ; max_index = Math . max ( max_index , fre [ x ] ) ; if ( dist >= N && ( ( max_index * dist ) == ( j - i + 1 ) ) ) count ++ ; } } return count ; } var s = " " ; var N = 3 ; document . write ( no_of_subString ( s , N ) ) ;