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

from copy import deepcopy
class Solution:
    def minimumScore(self, s: str, t: str) -> int:
        left=[-1]*len(t)
        right=[-1]*len(t)
        ind=defaultdict(deque)
        ind2=defaultdict(deque)
        for i in range(len(s)):
            ind[s[i]].append(i)
            ind2[s[i]].append(i)
        for i in range(len(t)):
            if ind[t[i]]:
                while i and  ind[t[i]] and ind[t[i]][0]<left[i-1]:
                    ind[t[i]].popleft()
                if ind[t[i]]:
                    left[i]=ind[t[i]].popleft()
        ind=ind2
        ans=len(t)
        cnt=0
        for i in range(len(t)-1,-1,-1):
            cnt+=1
            if ind2[t[i]]:
                while i+1<len(t) and ind[t[i]] and ind[t[i]][-1]>right[i+1]:
                    ind[t[i]].pop()
                if ind[t[i]]:
                    right[i]=ind[t[i]].pop()
                    ans=min(ans,len(t)-cnt)
            if i+1<len(t) and right[i+1]<right[i]:
                right[i]=-1
                break
        hi=len(left)-1
        for i in range(len(left)):
            if left[i]==-1:
                break
            l=i
            while  right[hi]<left[l]:
                if hi+1<len(left):
                    hi+=1
                else:
                    break
            while hi>l and right[hi]!=-1 and right[hi]>left[l]:
                th=hi-1
                hi=th
            ans=min(ans,hi-l)
                
        return max(ans,0)
23200