C++ | O(nlogn) | Sliding Window | Binary Search | Intuition | Approach
Intuition\n1. Say your answer is x.\n2. You will have a window of size x inside the string t, within which you remove characters. Say this window is from $t_i$ 
# Intuition\n1. Say your answer is `x`.\n2. You will have a window of size `x` inside the string `t`, within which you remove characters. Say this window is from $t_i$ to $t_{i+x-1}$\n3. For `x` to be the answer, $t_0t_1...t_{i-1}$ and $t_{i+x}t_{i+x+1}...t_{n}$ should be subsequenses of $t$ and earliest index of $t_{i-1}$ < latest index of $t_{i+x}$\n4. We can binary search for `x` over range `1` to `t.length()``\n\n# Approach\n1. Build a prefix array that stores for an index `i` in `t`, the earliest index in `s`, for which $t_0t_1..t_i$ is a subsequence of `s`.\n2. Build a suffix array that stores for an index `i` in `t`, the latest index in `s`, for which $t_it_{i+1}..t_n$ is a subsequence of `s`.\n3. Binary search for window length `x`.\n4. Slide a window of length `x` through `t`, if a subsquence is found before and after the window that satisfies the condition 3 in Intuition, we search for smaller windows\n\n# Complexity\n- Time complexity:\n`O(n*logn)`;\nwhere `n = t.length()``\n\n- Space complexity:\n`O(n)`\n\n# Code\n```cpp\nclass Solution {\npublic:\n    int minimumScore(string s, string t) {\n        int n = t.size();\n        int m = s.size();\n        int pre[n], suf[n];\n        int i = 0, j = 0;\n        while(i<n && j<m){\n            if(t[i] == s[j]){\n                pre[i] = j;\n                i++;\n                j++;\n            }else{\n                j++;\n            }\n        }\n        while(i<n){\n            pre[i++] = INT_MAX;\n        }\n        i = n-1; j = m-1;\n        while(i >= 0 && j >= 0){\n            if(t[i] == s[j]){\n                suf[i] = j;\n                i--;\n                j--;\n            }else{\n                j--;\n            }\n        }\n        while(i>=0){\n            suf[i--] = INT_MIN;\n        }\n        //checking if 0 is the answer\n        if(pre[n-1] != INT_MAX) return 0;\n        int low = 1, high = t.size();\n        bool pos;\n        while(low <= high){\n            int mid = low + (high - low)/2;\n            pos = 0;\n            for(int i = mid-1;i<n;i++){\n                int ll = (i == mid-1 ? -1 : pre[i-mid]);\n                int hh = (i == n-1 ? INT_MAX : suf[i+1]);\n                if(ll < hh){\n                    pos = 1;\n                    break;\n                }\n            }\n            if(pos){\n                high = mid - 1;\n            }else{\n                low = mid + 1;\n            }\n        }\n        return low;\n    }\n};\n```\n
['Binary Search', 'Sliding Window', 'C++']