Easy to understand O(n) space O(n) time well commented solution
Since only extreme ends have an impact on our solution, it makes sense to leave the left side block and right side block and delete the middle piece of string t
Since only extreme ends have an impact on our solution, it makes sense to leave the left side block and right side block and delete the middle piece of string t.\nWe define two arrays, one holding prefix data and the other suffix data, both of size n (n=size of string s).\n\nTime Complexity: O(n)\nSpace Complexity: O(n)\n\n```\nclass Solution {\npublic:\n    int minimumScore(string s, string t) {\n        int n=s.size(),j=0,res=1e9;\n        //declare 2 arrays: v1=prefix array, v2=suffix array\n        vector<int>v1(n),v2(n);\n        //Case 1- current element is part of prefix\n        for(int i=0;i<n;i++){\n            if(j<t.size() && s[i]==t[j]){\n                j++;\n            }\n            v1[i]=j;\n        }\n        j=t.size()-1;\n        for(int i=n-1;i>=0;i--){\n            v2[i]=j;\n            if(j>=0 && s[i]==t[j]){\n                j--;\n            }\n        }\n        //check result\n        for(int i=0;i<n;i++){\n            res=min(res,max(0,v2[i]-v1[i]+1));\n        }\n        //Case 2- current element is part of suffix\n        j=0;\n        for(int i=0;i<n;i++){\n            v1[i]=j;\n            if(j<t.size() && s[i]==t[j]){\n                j++;\n            }\n        }\n        //check result\n        j=t.size()-1;\n        for(int i=n-1;i>=0;i--){\n            if(j>=0 && s[i]==t[j]){\n                j--;\n            }\n            v2[i]=j;\n        }\n        for(int i=0;i<n;i++){\n            res=min(res,max(0,v2[i]-v1[i]+1));\n        }\n        return res;\n    }\n};\n```
['C']