Count of non | Java 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
import java . io . * ; import java . util . * ; class GFG { public static int count = 0 ; public static void countNumberOfStringsUtil ( int [ ] freq ) { for ( int i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] > 0 ) { freq [ i ] -- ; count ++ ; countNumberOfStringsUtil ( freq ) ; } } } public static int countNumberOfStrings ( String s ) { int [ ] freq = new int [ 26 ] ; Arrays . fill ( freq , 0 ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { freq [ s . charAt ( i ) - ' A ' ] ++ ; } countNumberOfStringsUtil ( freq ) ; return count ; } public static void main ( String [ ] args ) { String s = " AAABBC " ; System . out . println ( countNumberOfStrings ( s ) ) ; } }