With respect to a given <code>puzzle</code> string, a <code>word</code> is <em>valid</em> if both the following conditions are satisfied:
<ul>
	<li><code>word</code> contains the first letter of <code>puzzle</code>.</li>
	<li>For each letter in <code>word</code>, that letter is in <code>puzzle</code>.
	<ul>
		<li>For example, if the puzzle is <code>&quot;abcdefg&quot;</code>, then valid words are <code>&quot;faced&quot;</code>, <code>&quot;cabbage&quot;</code>, and <code>&quot;baggage&quot;</code>, while</li>
		<li>invalid words are <code>&quot;beefed&quot;</code> (does not include <code>&#39;a&#39;</code>) and <code>&quot;based&quot;</code> (includes <code>&#39;s&#39;</code> which is not in the puzzle).</li>
	</ul>
	</li>
</ul>
Return <em>an array </em><code>answer</code><em>, where </em><code>answer[i]</code><em> is the number of words in the given word list </em><code>words</code><em> that is valid with respect to the puzzle </em><code>puzzles[i]</code>.
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> words = [&quot;aaaa&quot;,&quot;asas&quot;,&quot;able&quot;,&quot;ability&quot;,&quot;actt&quot;,&quot;actor&quot;,&quot;access&quot;], puzzles = [&quot;aboveyz&quot;,&quot;abrodyz&quot;,&quot;abslute&quot;,&quot;absoryz&quot;,&quot;actresz&quot;,&quot;gaswxyz&quot;]
<strong>Output:</strong> [1,1,3,2,4,0]
<strong>Explanation:</strong> 
1 valid word for &quot;aboveyz&quot; : &quot;aaaa&quot; 
1 valid word for &quot;abrodyz&quot; : &quot;aaaa&quot;
3 valid words for &quot;abslute&quot; : &quot;aaaa&quot;, &quot;asas&quot;, &quot;able&quot;
2 valid words for &quot;absoryz&quot; : &quot;aaaa&quot;, &quot;asas&quot;
4 valid words for &quot;actresz&quot; : &quot;aaaa&quot;, &quot;asas&quot;, &quot;actt&quot;, &quot;access&quot;
There are no valid words for &quot;gaswxyz&quot; cause none of the words in the list contains letter &#39;g&#39;.
</pre>

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

<pre>
<strong>Input:</strong> words = [&quot;apple&quot;,&quot;pleas&quot;,&quot;please&quot;], puzzles = [&quot;aelwxyz&quot;,&quot;aelpxyz&quot;,&quot;aelpsxy&quot;,&quot;saelpxy&quot;,&quot;xaelpsy&quot;]
<strong>Output:</strong> [0,1,3,2,0]
</pre>

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

<ul>
	<li><code>1 &lt;= words.length &lt;= 10<sup>5</sup></code></li>
	<li><code>4 &lt;= words[i].length &lt;= 50</code></li>
	<li><code>1 &lt;= puzzles.length &lt;= 10<sup>4</sup></code></li>
	<li><code>puzzles[i].length == 7</code></li>
	<li><code>words[i]</code> and <code>puzzles[i]</code> consist of lowercase English letters.</li>
	<li>Each <code>puzzles[i] </code>does not contain repeated characters.</li>
</ul>

class TrieNode{
    public:
    TrieNode* chil[26];
    int val;
    TrieNode(){
        for(int x=0;x<26;x++){
            chil[x]=NULL;
        }
        val=0;

    }
};
class Trie{
    public:
    TrieNode *root;
    Trie(){
        root=new TrieNode();
    }
    void insert(string &s){
        int j=0;
        TrieNode *root1=root;
        while(j<s.length()){
            if(root1->chil[s[j]-'a']){
                root1=root1->chil[s[j]-'a'];
            }
            else{
                root1->chil[s[j]-'a']=new TrieNode();
                 root1=root1->chil[s[j]-'a'];


            }

            j++;
        }
        root1->val++;
        
    }
};
class Solution {
public:
int x1;
void ans1(int i,string &s,TrieNode* y,int f,int y1){
   
    if(i==s.length()){
        if(f==1){
       x1=x1+y->val;}
       return;
    }
    
    if(y->chil[s[i]-'a']){
        if(s[i]-'a'==y1){
        ans1(i+1,s,y->chil[s[i]-'a'],1,y1);
        }
        else{
            ans1(i+1,s,y->chil[s[i]-'a'],f,y1);

        }
    }
    ans1(i+1,s,y,f,y1);
    

}
    vector<int> findNumOfValidWords(vector<string>& words, vector<string>& puzzles) {
        vector<vector<vector<int>>> g1(26,vector<vector<int>>(26));
        int j1=0;
        vector<Trie*> t1(26);
        for(int x=0;x<26;x++){
            t1[x]=new Trie();
        }
        for(auto it:words){
            int j=0;
            map<char,int> m1;
           
            j=0;
            map<char,int> m2;
             m1[it[0]]=1;
            while(j<it.length()){
                
                    m2[it[j]]++;
                
                j++;
            }
            string s1="";
        
            for(auto it1:m2){
                s1.push_back(it1.first);
            }
            cout<<s1<<"\n";
            t1[0]->insert(s1);
            j1++;

        }
        vector<int> ans;
        cout<<t1[0]->root->val;
        for(auto it:puzzles){
            int j=0;
            string s1="";
            int rg=it[0]-'a';
            while(j<it.length()){
                s1.push_back(it[j]);
                j++;
            }
            sort(s1.begin(),s1.end());
            x1=0;
            
            ans1(0,s1,t1[0]->root,0,rg);
            
            ans.push_back(x1);

        }
        return ans;
        
    }
};
190600