Frequency of smallest character in first sentence less than that of second sentence | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countMinFreq ( string s ) { sort ( s . begin ( ) , s . end ( ) ) ; return count ( s . begin ( ) , s . end ( ) , s [ 0 ] ) ; } void countLessThan ( vector < string > & arr1 , vector < string > & arr2 ) { vector < int > freq ; for ( string s : arr2 ) { int f = countMinFreq ( s ) ; freq . push_back ( f ) ; } sort ( freq . begin ( ) , freq . end ( ) ) ; for ( string s : arr1 ) { int f = countMinFreq ( s ) ; auto it = upper_bound ( freq . begin ( ) , freq . end ( ) , f ) ; int cnt = freq . size ( ) - ( it - freq . begin ( ) ) ; cout << cnt << ' ▁ ' ; } } int main ( ) { vector < string > arr1 , arr2 ; arr1 = { " yyy " , " zz " } ; arr2 = { " x " , " xx " , " xxx " , " xxxx " } ; countLessThan ( arr1 , arr2 ) ; return 0 ; }