text: Pairs of complete strings in two sets of strings | Java implementation for find pairs of complete 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
code: class GFG { static int countCompletePairs ( String set1 [ ] , String set2 [ ] , int n , int m ) { int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { String concat = set1 [ i ] + set2 [ j ] ; int frequency [ ] = new int [ 26 ] ; for ( int k = 0 ; k < concat . length ( ) ; k ++ ) { frequency [ concat . charAt ( k ) - ' a ' ] ++ ; } int k ; for ( k = 0 ; k < 26 ; k ++ ) { if ( frequency [ k ] < 1 ) { break ; } } if ( k == 26 ) { result ++ ; } } } return result ; } static public void main ( String [ ] args ) { String set1 [ ] = { " abcdefgh " , " geeksforgeeks " , " lmnopqrst " , " abc " } ; String set2 [ ] = { " ijklmnopqrstuvwxyz " , " abcdefghijklmnopqrstuvwxyz " , " defghijklmnopqrstuvwxyz " } ; int n = set1 . length ; int m = set2 . length ; System . out . println ( countCompletePairs ( set1 , set2 , n , m ) ) ; } }