Simple prefix and suffix
Intuition\n Describe your first thoughts on how to solve this problem. \nCalculate the distance reached in t till any index in s .Both ways prefix and suffix.\n
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCalculate the distance reached in t till any index in s .Both ways prefix and suffix.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumScore(string s, string t) {\n        int n=s.length();\n        int m=t.length();\n        int st=0,en=m-1;\n        vector<int> pre(n,-1),suf(n+1,-1);\n        suf[n]=m;\n        for(int i=0;i<n;i++){\n            if(st<m&&s[i]==t[st]){\n                st++;\n            }\n            pre[i]=st;\n        }\n        for(int j=n-1;j>=0;j--){\n            if(en>=0&&s[j]==t[en]){\n                en--;\n            }\n            suf[j]=en+1;\n        }\n        int ans=INT_MAX;\n        for(int i=0;i<n;i++){\n            if(suf[i+1]<=pre[i])\n                return 0;\n            ans=min(ans,suf[i+1]-pre[i]);\n        }\n        ans=min(ans,suf[0]);\n        return ans;\n    }\n};\n```
['Prefix Sum', 'C++']