great explanation with intution
Code\n\nclass Solution {\npublic:\n    int minimumScore(string s, string t) {\n        // check if t can become a subsequence of s after some removal\n        /
# Code\n```\nclass Solution {\npublic:\n    int minimumScore(string s, string t) {\n        // check if t can become a subsequence of s after some removal\n        // only right and left is required so no need to consider remaining ones \n        // in between\n        // check for subsequence - if prefix does not overlap suffix\n        int n=s.length(), m=t.length();\n        vector<int> pref(m, n), suff(m, -1);\n        int p1=0, p2=0;\n        while(p2<m) // filling the prefix array\n        {\n            if(p1==n)\n            break;\n            if(s[p1] == t[p2])\n            {\n                pref[p2]=p1;\n                p2++;\n            }\n            p1++;\n        }\n        p1=n-1, p2=m-1;\n        while(p2>=0) // filling the suffix array\n        {\n            if(p1==-1)\n            break;\n            if(s[p1] == t[p2])\n            {\n                suff[p2]=p1;\n                p2--;\n            }\n            p1--;\n        }\n        // binary search to find the left and right pointer that has to\n        // be removed\n        int ans=m; // since maximum answer is the length of t\n        for(int l=0;l<m;l++) // fixing the left pointer\n        {\n            if(l>0 and pref[l-1]==n) // no need to check if we find a character we cannot form a subsequence with\n            break;\n            int ele=l==0?-1:pref[l-1]; // take the first valid suffix if left pointer is at index 0\n            int r=upper_bound(suff.begin(), suff.end(), ele)-suff.begin(); // find the first element with value greater than that of pref[l-1]\n            if(l==r) // it means whole string is subsequence of s\n            return 0;\n            ans=min(ans, r-l);\n        }\n        return ans;\n    }\n};\n```
['Two Pointers', 'Binary Search', 'C++']