<p>You are given two string arrays <code>words1</code> and <code>words2</code>.</p>

<p>A string <code>b</code> is a <strong>subset</strong> of string <code>a</code> if every letter in <code>b</code> occurs in <code>a</code> including multiplicity.</p>

<ul>
	<li>For example, <code>&quot;wrr&quot;</code> is a subset of <code>&quot;warrior&quot;</code> but is not a subset of <code>&quot;world&quot;</code>.</li>
</ul>

<p>A string <code>a</code> from <code>words1</code> is <strong>universal</strong> if for every string <code>b</code> in <code>words2</code>, <code>b</code> is a subset of <code>a</code>.</p>

<p>Return an array of all the <strong>universal</strong> strings in <code>words1</code>. You may return the answer in <strong>any order</strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> words1 = [&quot;amazon&quot;,&quot;apple&quot;,&quot;facebook&quot;,&quot;google&quot;,&quot;leetcode&quot;], words2 = [&quot;e&quot;,&quot;o&quot;]
<strong>Output:</strong> [&quot;facebook&quot;,&quot;google&quot;,&quot;leetcode&quot;]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> words1 = [&quot;amazon&quot;,&quot;apple&quot;,&quot;facebook&quot;,&quot;google&quot;,&quot;leetcode&quot;], words2 = [&quot;l&quot;,&quot;e&quot;]
<strong>Output:</strong> [&quot;apple&quot;,&quot;google&quot;,&quot;leetcode&quot;]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= words1.length, words2.length &lt;= 10<sup>4</sup></code></li>
	<li><code>1 &lt;= words1[i].length, words2[i].length &lt;= 10</code></li>
	<li><code>words1[i]</code> and <code>words2[i]</code> consist only of lowercase English letters.</li>
	<li>All the strings of <code>words1</code> are <strong>unique</strong>.</li>
</ul>

class Solution {
public:
    vector<string> wordSubsets(vector<string>& v, vector<string>& a) {
        int i,n=v.size(),m=a.size(),j,k,h;
        vector<string>o;
     o=v;
        vector<string>x;
        map<string,string>p;
        map<char,int>d;
         map<char,int>f;
        for(i=0;i<n;i++){
            string y=v[i];
        sort(v[i].begin(),v[i].end());
        string z=v[i];
        p[z]=y;
        }
        set<char>q;
        string s=a[0];
        for(i=0;i<a[0].size();i++)
        d[a[0][i]]++;
        for(i=1;i<a.size();i++){
            for(j=0;j<a[i].size();j++){
                 f[a[i][j]]++;
            }
             for(k=0;k<a[i].size();k++){
                q.insert(a[i][k]);
            }
            for(auto x:q){
              
                if(d.find(x)==d.end())
                d[x]=0;
                int c=max(f[x]-d[x],0);
                for(h=0;h<c;h++){
                    cout<<1;
                s=s+x;
                d[x]++;
                }
            }
            f.clear();
        }
        sort(s.begin(),s.end());
        cout<<s;
        for(i=0;i<n;i++){
            int j=0,k=0,c=0;
            while(j<v[i].size()&&k<s.size()){
                if(v[i][j]>s[k])
                break;
                else if(v[i][j]<s[k])
                j++;
                else{
                    c++;
                j++;
                k++;
                }
            }
            if(c==s.size())
            x.push_back(o[i]);
            c=0;
        }
        return x;
    }
};
131900