Count of times second string can be formed from the characters of first string | Python3 implementation of the approach ; Function to update the freq [ ] array to store the frequencies of all the characters of strr ; Update the frequency of the characters ; Function to return the maximum count of times patt can be formed using the characters of strr ; To store the frequencies of all the characters of strr ; To store the frequencies of all the characters of patt ; To store the result ; For every character ; If the current character doesn 't appear in patt ; Update the result ; Driver code
MAX = 26 NEW_LINE def updateFreq ( strr , freq ) : NEW_LINE INDENT lenn = len ( strr ) NEW_LINE for i in range ( lenn ) : NEW_LINE INDENT freq [ ord ( strr [ i ] ) - ord ( ' a ' ) ] += 1 NEW_LINE DEDENT DEDENT def maxCount ( strr , patt ) : NEW_LINE INDENT strrFreq = [ 0 for i in range ( MAX ) ] NEW_LINE updateFreq ( strr , strrFreq ) NEW_LINE pattFreq = [ 0 for i in range ( MAX ) ] NEW_LINE updateFreq ( patt , pattFreq ) NEW_LINE ans = 10 ** 9 NEW_LINE for i in range ( MAX ) : NEW_LINE INDENT if ( pattFreq [ i ] == 0 ) : NEW_LINE INDENT continue NEW_LINE DEDENT ans = min ( ans , strrFreq [ i ] // pattFreq [ i ] ) NEW_LINE DEDENT return ans NEW_LINE DEDENT strr = " geeksforgeeks " NEW_LINE patt = " geeks " NEW_LINE print ( maxCount ( strr , patt ) ) NEW_LINE