C++| Binary Search + Sliding Window + Prefix array | O(N*log(N))
Hint: Let left and right be the minimum and maximum index among all removed characters. If we remove all characters from left to right ( remove sustring t[left:
**Hint:** Let `left` and `right` be the minimum and maximum index among all removed characters. If we remove all characters from left to right ( remove sustring t[left:right] from string `t`), it will not change the result. Find the min length of the substring to be removed.\n`Note: right-left+1 is the length of substring t[left:right]`\n## Approach: \n* With the help of Binary search, we can find the lenght of the smallest substring to be removed.\n* Now, once we have a lenght (say **k**) to be removed, we can make use of prefix & suffix array and sliding window to find out whether it\'s possible to remove any substring of length **k** to make `t` a subsequence of `s` or not.\n* Make a prefix array `left` where **left[i]** is the min index of `s` such that substring t[0:i] is a subsequence of substring s[0:left[i]]\n* Make a suffix array `right` where **right[i]** is the max index of `s` such that substring t[i:] is a subsequence of substring s[left[i]:]\n* Now apply the Sliding window. See the implementation for more understanding\n```\nclass Solution {\npublic:\n    void makeprefix(vector<int>& left,vector<int>& right,string &s,string &t){\n        for(int i = 0,j = 0; i<s.size() && j<t.size();++i){\n            if(s[i]==t[j]){\n                left[j] = i; j++;\n            }\n        }\n        for(int i = s.size()-1,j = t.size()-1;i>=0 && j>=0;--i){\n            if(s[i]==t[j]){\n                right[j] = i; j--;\n            }\n        }\n    }\n    bool find(vector<int>& left,vector<int>& right,int m,int n){\n        if(m==n) return 1;\n        if(right[m]!=-1 || left[n-m-1]!=-1) return 1;\n        for(int i = 0,j = m+1; j<n ;++i,++j){\n            if(left[i]!=-1 && right[j]!=-1 && left[i]<right[j]) return 1;\n        }\n        return 0;\n    }\n    int minimumScore(string s, string t) {\n        vector<int> left(t.size(),-1),right(t.size(),-1);\n        makeprefix(left,right,s,t);\n        int l = 0,h = t.size(),re = -1;\n        while(l<=h){\n            int m = (l+h)/2;\n            if(find(left,right,m,t.size())) { re = m; h = m-1; }\n            else l = m+1;\n        }\n        return re;\n    }\n};\n```\n**Upvote** if it helps
['C', 'Sliding Window', 'Binary Tree']