<p>Given a string <code>s</code> and an array of strings <code>words</code>, return <em>the number of</em> <code>words[i]</code> <em>that is a subsequence of</em> <code>s</code>.</p>

<p>A <strong>subsequence</strong> of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.</p>

<ul>
	<li>For example, <code>&quot;ace&quot;</code> is a subsequence of <code>&quot;abcde&quot;</code>.</li>
</ul>

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

<pre>
<strong>Input:</strong> s = &quot;abcde&quot;, words = [&quot;a&quot;,&quot;bb&quot;,&quot;acd&quot;,&quot;ace&quot;]
<strong>Output:</strong> 3
<strong>Explanation:</strong> There are three strings in words that are a subsequence of s: &quot;a&quot;, &quot;acd&quot;, &quot;ace&quot;.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;dsahjpjauf&quot;, words = [&quot;ahjpjau&quot;,&quot;ja&quot;,&quot;ahbwzgqnuk&quot;,&quot;tnmlanowax&quot;]
<strong>Output:</strong> 2
</pre>

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

<ul>
	<li><code>1 &lt;= s.length &lt;= 5 * 10<sup>4</sup></code></li>
	<li><code>1 &lt;= words.length &lt;= 5000</code></li>
	<li><code>1 &lt;= words[i].length &lt;= 50</code></li>
	<li><code>s</code> and <code>words[i]</code> consist of only lowercase English letters.</li>
</ul>

bool isSubsequence(string s, string t) {
        if(s==""){
            return true;
        }
        if(t==""){
            return false;
        }
        int n = s.length();
        int n1 = t.length();
        vector<int>Memo(n1,-1);
        int Max = -1;
        if(t[0]==s[0]){
            Memo[0] = 0;
            Max = 0;
        }
        
        for(int i =1;i<n1;i++){
            if(s[Memo[i-1]+1]==t[i]){
                Memo[i]=1+Memo[i-1];
            }
            else{
                Memo[i]=Memo[i-1];
            }
            Max = max(Max,Memo[i]);
            if(Max == n-1){
                return true;
            }
        }
        return false;
    }
class Solution {
public:
    int numMatchingSubseq(string s, vector<string>& words) {
        int n = words.size();
        
        map<string,int>st1;
        int cnt = 0;
        for(int i = 0;i<n;i++){
            
            st1[words[i]]=0;
        }
        for(int i = 0;i<n;i++){
            if(st1[words[i]]==0){
                if(isSubsequence(words[i],s)){
                    st1[words[i]]=1;
                    cnt++;
                }
                else{
                    st1[words[i]]=-1;
                }
            }else if(st1[words[i]]==1){
                cnt++;
            }
        }
        return cnt;
    }
};
293966