Frequency of smallest character in first sentence less than that of second sentence | Python3 program for the above approach ; Function to count the frequency of minimum character ; Sort the string s ; Return the count with smallest character ; Function to count number of frequency of smallest character of string arr1 [ ] is less than the string in arr2 [ ] ; To store the frequency of smallest character in each string of arr2 ; Traverse the arr2 [ ] ; Count the frequency of smallest character in string s ; Append the frequency to freq [ ] ; Sort the frequency array ; Traverse the array arr1 [ ] ; Count the frequency of smallest character in string s ; find the element greater than f ; Find the count such that arr1 [ i ] < arr2 [ j ] ; Print the count ; Driver Code ; Function Call
from bisect import bisect_right as upper_bound NEW_LINE def countMinFreq ( s ) : NEW_LINE INDENT s = sorted ( s ) NEW_LINE x = 0 NEW_LINE for i in s : NEW_LINE INDENT if i == s [ 0 ] : NEW_LINE INDENT x += 1 NEW_LINE DEDENT DEDENT return x NEW_LINE DEDENT def countLessThan ( arr1 , arr2 ) : NEW_LINE INDENT freq = [ ] NEW_LINE for s in arr2 : NEW_LINE INDENT f = countMinFreq ( s ) NEW_LINE freq . append ( f ) NEW_LINE DEDENT feq = sorted ( freq ) NEW_LINE for s in arr1 : NEW_LINE INDENT f = countMinFreq ( s ) ; NEW_LINE it = upper_bound ( freq , f ) NEW_LINE cnt = len ( freq ) - it NEW_LINE print ( cnt , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr1 = [ " yyy " , " zz " ] NEW_LINE arr2 = [ " x " , " xx " , " xxx " , " xxxx " ] NEW_LINE countLessThan ( arr1 , arr2 ) ; NEW_LINE DEDENT