text: Print all Strings from array A [ ] having all strings from array B [ ] as subsequence | Function to find strings from A [ ] having all strings in B [ ] as subsequence ; Calculate respective sizes ; Stores the answer ; Stores the frequency of each character in strings of A [ ] ; Compute the frequencies of characters of all strings ; Stores the frequency of each character in strings of B [ ] each character of a string in B [ ] ; If the frequency of a character in B [ ] exceeds that in A [ ] ; A string exists in B [ ] which is not a proper subset of A [ i ] ; If all strings in B [ ] are proper subset of A [ ] ; Push the string in resultant vector ; If any string is found ; Print those strings ; Otherwise ; Driver code
code: function UniversalSubset ( A , B ) { var n1 = A . length ; var n2 = B . length ; var res = [ ] ; var A_fre = Array . from ( Array ( n1 ) , ( ) => Array ( 26 ) ) ; for ( var i = 0 ; i < n1 ; i ++ ) { for ( var j = 0 ; j < 26 ; j ++ ) A_fre [ i ] [ j ] = 0 ; } for ( var i = 0 ; i < n1 ; i ++ ) { for ( var j = 0 ; j < A [ i ] . length ; j ++ ) { A_fre [ i ] [ A [ i ] . charCodeAt ( j ) - ' ' . charCodeAt ( 0 ) ] ++ ; } } var B_fre = Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < n2 ; i ++ ) { var arr = Array ( 26 ) . fill ( 0 ) ; for ( var j = 0 ; j < B [ i ] . length ; j ++ ) { arr [ B [ i ] . charCodeAt ( j ) - ' ' . charCodeAt ( 0 ) ] ++ ; B_fre [ B [ i ] . charCodeAt ( j ) - ' ' . charCodeAt ( 0 ) ] = Math . max ( B_fre [ B [ i ] . charCodeAt ( j ) - ' ' . charCodeAt ( 0 ) ] , arr [ B [ i ] . charCodeAt ( j ) - ' ' . charCodeAt ( 0 ) ] ) ; } } for ( var i = 0 ; i < n1 ; i ++ ) { var flag = 0 ; for ( var j = 0 ; j < 26 ; j ++ ) { if ( A_fre [ i ] [ j ] < B_fre [ j ] ) { flag = 1 ; break ; } } if ( flag == 0 ) res . push ( A [ i ] ) ; } if ( res . length > 0 ) { for ( var i = 0 ; i < res . length ; i ++ ) { for ( var j = 0 ; j < res [ i ] . length ; j ++ ) document . write ( res [ i ] [ j ] ) ; } document . write ( " " ) ; } else document . write ( " " ) ; } var A = [ " " , " " , " " ] ; var B = [ " " , " " ] ; UniversalSubset ( A , B ) ;