JAVA | Easy Explained | votrubac's solution explained
Intuition\n Describe your first thoughts on how to solve this problem. \nBased on the problem description, we need to find the longest prefix + suffix of t that
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nBased on the problem description, we need to find the longest prefix + suffix of t that is a subsequence of s beacuse it was hte way we remove elements from middle. Thus the score would be minimum.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFor each matched character in t, we remember the corresponding point in s in the dp array. This is our suffix.\nThen we go left-to-right building our prefix. For each prefix, we determine the longest suffix using dp.\n**Note 2** We use a loop to prevent overlapping and make it move till its not overlapped , then calculate minimum among the answer.\n**Note 2** res condition is checked that if t as complete is a subsequence of s then no need to remove any thing from it.\n\n\n# Code\n```\nclass Solution {\n    public int minimumScore(String s, String t) \n    {\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        {\n            if(s.charAt(i) == t.charAt(k))\n            {\n                dp[k] = i;\n                k--;\n            }\n        }\n        int res = k+1;\n        if(res == 0)\n        return 0;\n        for(int i = 0,j=0;i<ss && j<st;i++)\n        {\n            if(s.charAt(i) == t.charAt(j))\n            {\n                while(k<st && dp[k]<=i)\n                {\n                    k++;\n                }\n                j++;\n                res = Math.min(res, k - (j));\n            }\n        }\n        return res;\n    \n    }\n}\n```
['Java']