Count of non | Python3 implementation of the above approach ; Function to find the count of the number of strings ; Loop to iterate over the frequency of character of string ; Reduce the frequency of current element ; Recursive call ; Backtrack ; Function to count the number of non - empty sequences ; store the frequency of each character ; Maintain the frequency ; Driver Code ; Function Call
count = 0 NEW_LINE def countNumberOfStringsUtil ( freq , Count ) : NEW_LINE INDENT global count NEW_LINE count = Count NEW_LINE for i in range ( 26 ) : NEW_LINE INDENT if ( freq [ i ] > 0 ) : NEW_LINE INDENT freq [ i ] -= 1 NEW_LINE count += 1 NEW_LINE countNumberOfStringsUtil ( freq , count ) ; NEW_LINE freq [ i ] += 1 NEW_LINE DEDENT DEDENT DEDENT def countNumberOfStrings ( s ) : NEW_LINE INDENT global count NEW_LINE global freq NEW_LINE freq = [ 0 for i in range ( 26 ) ] NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT freq [ ord ( s [ i ] ) - ord ( ' A ' ) ] += 1 NEW_LINE DEDENT countNumberOfStringsUtil ( freq , count ) ; NEW_LINE return count NEW_LINE DEDENT s = " AAABBC " NEW_LINE print ( countNumberOfStrings ( s ) ) NEW_LINE