Count of strings in the first array which are smaller than every string in the second array | C # implementation of the approach ; Function to count the number of smaller strings in A [ ] for every String in B [ ] ; Count the frequency of all characters ; Iterate for all possible strings in A [ ] ; Increase the frequency of every character ; Check for the smallest character 's frequency ; Get the smallest character frequency ; Insert it in the vector ; Sort the count of all the frequency of the smallest character in every string ; Iterate for every String in B [ ] ; Hash set every frequency 0 ; Count the frequency of every character ; Find the frequency of the smallest character ; Count the number of strings in A [ ] which has the frequency of the smaller character less than the frequency of the smaller character of the String in B [ ] ; Store the answer ; Function to print the answer ; Get the answer ; Print the number of strings for every answer ; Driver code
using System ; using System . Collections . Generic ; public class GFG { static int MAX = 26 ; static List < int > findCount ( String [ ] a , String [ ] b , int n , int m ) { int [ ] freq = new int [ MAX ] ; List < int > smallestFreq = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = a [ i ] ; for ( int l = 0 ; l < freq . Length ; l ++ ) freq [ l ] = 0 ; for ( int j = 0 ; j < s . Length ; j ++ ) { freq [ s [ j ] - ' a ' ] ++ ; } for ( int j = 0 ; j < MAX ; j ++ ) { if ( freq [ j ] > 0 ) { smallestFreq . Add ( freq [ j ] ) ; break ; } } } smallestFreq . Sort ( ) ; List < int > ans = new List < int > ( ) ; for ( int i = 0 ; i < m ; i ++ ) { String s = b [ i ] ; for ( int l = 0 ; l < freq . Length ; l ++ ) freq [ l ] = 0 ; for ( int j = 0 ; j < s . Length ; j ++ ) { freq [ s [ j ] - ' a ' ] ++ ; } int frequency = 0 ; for ( int j = 0 ; j < MAX ; j ++ ) { if ( freq [ j ] > 0 ) { frequency = freq [ j ] ; break ; } } int [ ] array = new int [ smallestFreq . Count ] ; int k = 0 ; foreach ( int val in smallestFreq ) { array [ k ] = val ; k ++ ; } int ind = lower_bound ( array , 0 , smallestFreq . Count , frequency ) ; ans . Add ( ind ) ; } return ans ; } static int lower_bound ( int [ ] a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } static void printAnswer ( String [ ] a , String [ ] b , int n , int m ) { List < int > ans = findCount ( a , b , n , m ) ; foreach ( int it in ans ) { Console . Write ( it + " ▁ " ) ; } } public static void Main ( String [ ] args ) { String [ ] A = { " aaa " , " aa " , " bdc " } ; String [ ] B = { " cccch " , " cccd " } ; int n = A . Length ; int m = B . Length ; printAnswer ( A , B , n , m ) ; } }