<p>You are given two strings <code>s</code> and <code>t</code>.</p>

<p>You are allowed to remove any number of characters from the string <code>t</code>.</p>

<p>The score of the string is <code>0</code> if no characters are removed from the string <code>t</code>, otherwise:</p>

<ul>
	<li>Let <code>left</code> be the minimum index among all removed characters.</li>
	<li>Let <code>right</code> be the maximum index among all removed characters.</li>
</ul>

<p>Then the score of the string is <code>right - left + 1</code>.</p>

<p>Return <em>the minimum possible score to make </em><code>t</code><em>&nbsp;a subsequence of </em><code>s</code><em>.</em></p>

<p>A <strong>subsequence</strong> of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., <code>&quot;ace&quot;</code> is a subsequence of <code>&quot;<u>a</u>b<u>c</u>d<u>e</u>&quot;</code> while <code>&quot;aec&quot;</code> is not).</p>

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

<pre>
<strong>Input:</strong> s = &quot;abacaba&quot;, t = &quot;bzaa&quot;
<strong>Output:</strong> 1
<strong>Explanation:</strong> In this example, we remove the character &quot;z&quot; at index 1 (0-indexed).
The string t becomes &quot;baa&quot; which is a subsequence of the string &quot;abacaba&quot; and the score is 1 - 1 + 1 = 1.
It can be proven that 1 is the minimum score that we can achieve.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;cde&quot;, t = &quot;xyz&quot;
<strong>Output:</strong> 3
<strong>Explanation:</strong> In this example, we remove characters &quot;x&quot;, &quot;y&quot; and &quot;z&quot; at indices 0, 1, and 2 (0-indexed).
The string t becomes &quot;&quot; which is a subsequence of the string &quot;cde&quot; and the score is 2 - 0 + 1 = 3.
It can be proven that 3 is the minimum score that we can achieve.
</pre>

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

<ul>
	<li><code>1 &lt;= s.length, t.length &lt;= 10<sup>5</sup></code></li>
	<li><code>s</code> and <code>t</code> consist of only lowercase English letters.</li>
</ul>

class Solution:

    def minimumScore(self, s: str, t: str) -> int:
        # s_len, t_len = len(s), len(t)

        # j = 0
        # prefix = []
        # for i in range(s_len):
        #     # store the matching characters scanning left to right
        #     if s[i] == t[j]:
        #         prefix.append(i)
        #         j += 1
        #     # break if whole of t is covered
        #     if j >= t_len:
        #         break
        # print("prefix = ", prefix)

        # # j now points to 1 past the last matched character in t from the left

        # # the max score is remove the rightmost character in t, and the score then would be
        # #   (t_len - 1) - (j-1) = t_len - j
        # res = t_len -j  

        # # start scanning from the rightmost character
        # k = t_len - 1
        # suffix = []
        # for i in  range(s_len-1, -1, -1):
        #     if s[i] == t[k]:
        #         # store index of matching characters and decrement index of t
        #         suffix.append(i)
        #         k -= 1
        #     if k < 0:
        #         break
        # print("suffix = ", suffix)
        
        # # now update the score to the rightmost character to be deleted
        # # res = (k+1) - (j-1)
        # res = min(res, k+1)
        # return 0

        s_len, t_len = len(s), len(t)
        suffix = t_len * [-1]
        k = t_len - 1
        for idx in range(s_len-1, -1, -1):
            if s[idx] == t[k]:
                suffix[k] = idx
                k -= 1
            if k < 0:
                break
        
        print("suffix = ", suffix)
        res = k + 1  # remove all elements 0, 1, 2, .., k

        j = 0
        l = 0
        for idx in range(s_len):
            # Note: we skip over all characters in s that does not match with the first 
            # charac in t ==> it would match at some idx though unless nothing matches and
            # we are done. 

            if s[idx] == t[j]:
                # use the suffix to traverse the subsequence until we find the 
                # suffix begginning that exceeds the current idx

                while l < t_len and suffix[l] <= idx:
                    l += 1
                # now l is either out of t or points to the start of suffix of t
                j += 1

                # 
                value = max(0, l - j)
                res = min(res, value)
            if j >= t_len:
                break
        return res

        


    
        
18700