<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>

from copy import copy

class Solution:

    def get_subsequence_cnt(self, s):
        if not s:
            return []
        else:
            cc = []
            prev_char = s[0]
            char_count = 1
            for i in range(1,len(s)):
                if s[i] == prev_char:
                    char_count += 1
                else:
                    cc.append([prev_char, char_count])
                    char_count = 1
                    prev_char = s[i]
            else:
                cc.append([prev_char, char_count])
            return cc


    def is_sub_sequence(self, ws, fss1):
        fss = copy(fss1)
        i,j = 0, 0

        while(i<len(ws) and j < len(fss)):
            if ws[i][0] == fss[j][0]:
                if ws[i][1] <= fss[j][1]:
                    i+=1
                    j+=1
                else:
                    ws[i][1] -= fss[j][1]
                    j+=1
            else:
                j+=1
            
            if len(fss) - j < len(ws) - i:
                return False

        return True




    def numMatchingSubseq(self, s: str, words) -> int:
        ls = len(s)
        if not s:
            return 0

        fss = self.get_subsequence_cnt(s)
        cnt = 0
        for w in words:
            if not w:
                continue
            if len(w) > ls:
                continue

            ws = self.get_subsequence_cnt(w)
            if len(ws) > len(fss):
                continue
            elif self.is_sub_sequence(ws, fss):
                cnt+=1
                print(w)
        
        return cnt


22300