text: Print all Strings from array A [ ] having all strings from array B [ ] as subsequence | C # program to implement the above approach ; 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: using System ; using System . Collections . Generic ; class GFG { static void UniversalSubset ( List < String > A , List < String > B ) { int n1 = A . Count ; int n2 = B . Count ; List < String > res = new List < String > ( ) ; int [ , ] A_fre = new int [ n1 , 26 ] ; for ( int i = 0 ; i < n1 ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) A_fre [ i , j ] = 0 ; } for ( int i = 0 ; i < n1 ; i ++ ) { for ( int j = 0 ; j < A [ i ] . Length ; j ++ ) { A_fre [ i , A [ i ] [ j ] - ' a ' ] ++ ; } } int [ ] B_fre = new int [ 26 ] ; for ( int i = 0 ; i < n2 ; i ++ ) { int [ ] arr = new int [ 26 ] ; for ( int j = 0 ; j < B [ i ] . Length ; j ++ ) { arr [ B [ i ] [ j ] - ' a ' ] ++ ; B_fre [ B [ i ] [ j ] - ' a ' ] = Math . Max ( B_fre [ B [ i ] [ j ] - ' a ' ] , arr [ B [ i ] [ j ] - ' a ' ] ) ; } } for ( int i = 0 ; i < n1 ; i ++ ) { int flag = 0 ; for ( int j = 0 ; j < 26 ; j ++ ) { if ( A_fre [ i , j ] < B_fre [ j ] ) { flag = 1 ; break ; } } if ( flag == 0 ) res . Add ( A [ i ] ) ; } if ( res . Count != 0 ) { for ( int i = 0 ; i < res . Count ; i ++ ) { for ( int j = 0 ; j < res [ i ] . Length ; j ++ ) Console . Write ( res [ i ] [ j ] ) ; } Console . Write ( " ▁ " ) ; } else Console . Write ( " - 1" ) ; } public static void Main ( String [ ] args ) { List < String > A = new List < String > ( ) ; A . Add ( " geeksforgeeks " ) ; A . Add ( " topcoder " ) ; A . Add ( " leetcode " ) ; List < String > B = new List < String > ( ) ; B . Add ( " geek " ) ; B . Add ( " ee " ) ; UniversalSubset ( A , B ) ; } }