Count of strings in the first array which are smaller than every string in the second array | JavaScript 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
const MAX = 26 ; function findCount ( a , b , n , m ) { var freq = new Array ( MAX ) . fill ( 0 ) ; var smallestFreq = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { var s = a [ i ] ; for ( var l = 0 ; l < freq . length ; l ++ ) freq [ l ] = 0 ; for ( var j = 0 ; j < s . length ; j ++ ) { freq [ s [ j ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } for ( var j = 0 ; j < MAX ; j ++ ) { if ( freq [ j ] > 0 ) { smallestFreq . push ( freq [ j ] ) ; break ; } } } smallestFreq . sort ( ) ; var ans = [ ] ; for ( var i = 0 ; i < m ; i ++ ) { var s = b [ i ] ; for ( var l = 0 ; l < freq . length ; l ++ ) freq [ l ] = 0 ; for ( var j = 0 ; j < s . length ; j ++ ) { freq [ s [ j ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } var frequency = 0 ; for ( var j = 0 ; j < MAX ; j ++ ) { if ( freq [ j ] > 0 ) { frequency = freq [ j ] ; break ; } } var array = new Array ( smallestFreq . length ) . fill ( 0 ) ; var k = 0 ; for ( const val of smallestFreq ) { array [ k ] = val ; k ++ ; } var ind = lower_bound ( array , 0 , smallestFreq . length , frequency ) ; ans . push ( ind ) ; } return ans ; } function lower_bound ( a , low , high , element ) { while ( low < high ) { var middle = low + parseInt ( ( high - low ) / 2 ) ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } function printAnswer ( a , b , n , m ) { var ans = findCount ( a , b , n , m ) ; for ( const it of ans ) { document . write ( it + " " ) ; } } var A = [ " " , " " , " " ] ; var B = [ " " , " " ] ; var n = A . length ; var m = B . length ; printAnswer ( A , B , n , m ) ;