15 lines | C++ | O(n)
````\nclass Solution {\npublic:\n    int minimumScore(string s, string t) {\n        int n = s.size();\n        int m = t.size();\n        vector pre_mch(m);\n 
````\nclass Solution {\npublic:\n    int minimumScore(string s, string t) {\n        int n = s.size();\n        int m = t.size();\n        vector<int> pre_mch(m);\n        vector<int> suf_mch(n+1,2*m+1);\n        \n        int cur = 0;\n        for (int i=0; i<m; i++){\n            while (cur < n && s[cur] != t[i]) \n                cur++;\n            pre_mch[i] = cur++;\n        }\n        \n        cur = n-1;\n        for (int i=m-1; i>=0; i--){\n            while (cur >= 0 && s[cur] != t[i]){ \n                suf_mch[cur--] = i+1;}\n            if(cur>=0) suf_mch[cur--] = i;\n        }\n\n        int ans = min(m,suf_mch[0]);\n        for (int i=0; i<m; i++){\n            if (pre_mch[i] < n) ans = min(ans, m-i-1);\n            ans = min(ans, max(0, suf_mch[min(n,pre_mch[i]+1)]-i-1));\n        }\n        return ans;\n    }\n};
['C++']