Pairs of complete strings in two sets of strings | Returns count of complete pairs from set [ 0. . n - 1 ] and set2 [ 0. . m - 1 ] ; Consider all pairs of both strings ; Create a concatenation of current pair ; Compute frequencies of all characters in the concatenated String . ; If frequency of any character is not greater than 0 , then this pair is not complete . ; Driver code
function countCompletePairs ( set1 , set2 , n , m ) { let result = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { let concat = set1 [ i ] + set2 [ j ] ; let frequency = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { frequency [ i ] = 0 ; } for ( let k = 0 ; k < concat . length ; k ++ ) { frequency [ concat [ k ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } let k ; for ( k = 0 ; k < 26 ; k ++ ) { if ( frequency [ k ] < 1 ) { break ; } } if ( k == 26 ) { result ++ ; } } } return result ; } let set1 = [ " " , " " , " " , " " ] ; let set2 = [ " " , " " , " " ] let n = set1 . length ; let m = set2 . length ; document . write ( countCompletePairs ( set1 , set2 , n , m ) ) ;