Using binary search and prefix - suffix
\n\n# Code\n\nclass Solution {\npublic:\n\n    int util(vector<int>&v, int prev) {\n        int l = 0, r = v.size() - 1, id = -1;\n        while(l <= r) {\n    
\n\n# Code\n```\nclass Solution {\npublic:\n\n    int util(vector<int>&v, int prev) {\n        int l = 0, r = v.size() - 1, id = -1;\n        while(l <= r) {\n            int mid = (l + r)/2;\n            if(v[mid] > prev) {\n                id = v[mid];\n                r = mid - 1;\n            } else {\n                l = mid + 1;\n            }\n        }\n        return id;\n    }\n\n    int util2(vector<int>&v, int prev) {\n        int l = 0, r = v.size() - 1, id = -1;\n        while(l <= r) {\n            int mid = (l + r)/2;\n            if(v[mid] < prev) {\n                id = v[mid];\n                l = mid + 1;\n            } else {\n                r = mid - 1;\n            }\n        }\n        return id;\n    }\n\n    bool check(int x, vector<int>& pre, vector<int>& suff) {\n        for(int i = 0 ; i <= pre.size() - x ; i++) {\n            if(i > 0 ) {\n                if(i + x < pre.size()) {\n                    if(pre[i - 1] >= 0 && suff[i + x] >= 0 && pre[i - 1] < suff[i + x])\n                        return true;\n                }else {\n                    if(pre[i - 1] >= 0)\n                        return true;\n                }\n            }else if(i + x < suff.size() && suff[i + x] >= 0)\n                return true;\n        }\n        return false;\n    }\n\n    int minimumScore(string s, string t) {\n        int n = s.length();\n        map<int,int>mp;\n        vector<vector<int>>v(26);\n        for(int i = 0 ; i < n ; i++)\n            v[s[i] - \'a\'].push_back(i);\n        int l = t.length(), r = -1, prev = -1;\n        vector<int>pre(l), suff(l);\n        for(int i = 0 ; i < t.length() ; i++) {\n            int x = util(v[t[i] - \'a\'],prev);\n            if(x == -1) {\n                pre[i] = -1;\n                break;\n            } else{\n                pre[i] = x;\n                prev = x;\n            }\n        }\n        prev = n;\n        for(int i = t.length() - 1 ; i >= 0 ; i--) {\n            int x = util2(v[t[i] - \'a\'],prev);\n            if(x == -1) {\n                suff[i] = -1;\n                break;\n            } else {\n                suff[i] = x;\n                prev = x;\n            }\n        }\n        for(int i = suff.size() - 2 ; i >= 0 ; i--) {\n            if(suff[i + 1] == -1)\n                suff[i] = -1;\n        }\n        for(int i = 1 ; i < pre.size() ; i++) {\n            if(pre[i - 1] == -1)\n                pre[i] = -1;\n        }\n        l = 0, r = t.length();\n        int id = r;\n        while(l <= r) {\n            int mid = (l + r)/2;\n            if(check(mid,pre,suff)) {\n                id = mid;\n                r = mid - 1;\n            } else {\n                l = mid + 1;\n            }\n        }\n        return id;\n    }\n};\n```
['Binary Search', 'C++']