Right and Left O(n)
Based on the problem description, we need to find the longest prefix + suffix of t that is a subsequence of s.\n\nWe first match t starting from the right.\n\nF
Based on the problem description, we need to find the longest prefix + suffix of `t` that is a subsequence of `s`.\n\nWe first match `t` starting from the right.\n\nFor each matched character in `t`, we remember the corresponding point in `s` in the `dp` array. This is our suffix.\n\nThen we go left-to-right building our prefix. For each prefix, we determine the longest suffix using `dp`.\n\n![image](https://assets.leetcode.com/users/images/927960ab-f214-4294-88bb-1891c4adafe9_1676178007.1489158.png)\n\n**C++**\n```cpp\nint minimumScore(string s, string t) {\n    int ss = s.size(), st = t.size(), k = st - 1;\n    vector<int> dp(st, -1);\n    for (int i = ss - 1; i >= 0 && k >= 0; --i)\n        if (s[i] == t[k])\n            dp[k--] = i;\n    int res = k + 1;\n    for (int i = 0, j = 0; i < ss && j < st && res > 0; ++i)\n        if (s[i] == t[j]) {\n            for (; k < t.size() && dp[k] <= i; ++k);\n            res = min(res, k - (++j));\n        }\n    return res;\n}\n```\n**Java**\n```java\npublic int minimumScore(String s, String t) {\n    int ss = s.length(), st = t.length(), k = st - 1;\n    int[] dp = new int[st];\n    Arrays.fill(dp, -1);\n    for (int i = ss - 1; i >= 0 && k >= 0; --i)\n        if (s.charAt(i) == t.charAt(k))\n            dp[k--] = i;\n    int res = k + 1;\n    for (int i = 0, j = 0; i < ss && j < st && res > 0; ++i)\n        if (s.charAt(i) == t.charAt(j)) {\n            for (; k < st && dp[k] <= i; ++k);\n            res = Math.min(res, k - (++j));\n        }\n    return res;\n}\n```
['C', 'Java']