Count of non | C ++ 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 ; freq [ i ] ++ ; backtrack ; Function to count the number of non - empty sequences ; store the frequency of each character ; Maintain the frequency ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void countNumberOfStringsUtil ( vector < int > & freq , int & count ) { for ( int i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] > 0 ) { freq [ i ] -- ; count ++ ; countNumberOfStringsUtil ( freq , count ) ; } } } int countNumberOfStrings ( string s ) { vector < int > freq ( 26 , 0 ) ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { freq [ s [ i ] - ' A ' ] ++ ; } int count = 0 ; countNumberOfStringsUtil ( freq , count ) ; return count ; } int main ( ) { string s = " AAABBC " ; cout << countNumberOfStrings ( s ) ; return 0 ; }