C++ commented code (Find longest suffix secured for each prefix)
Complexity\n- Time complexity: O(N log N)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(M)\n Add your space complexity here, e.g. O(n) \n
# Complexity\n- Time complexity: $$O(N log N)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(M)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumScore(string s, string t) {\n        int n=s.length(), m=t.length();\n\n        vector<int> l(m,-1),r(m,-1);\n\n        int j=0;\n        //longes prefix available\n        for(int i=0;i<n;i++){\n            if(j>=m){\n                break;\n            }\n            if(s[i]==t[j]){\n                l[j]=i;\n                j++;\n            }\n        }\n\n        j=m-1;\n        //longest suffix available\n        for(int i=n-1;i>=0;i--){\n            if(j<0){\n                break;\n            }\n            if(s[i]==t[j]){\n                r[j]=i;\n                j--;\n            }\n        }\n\n        int ans=m;\n        //ans if suffix and prefix has to removed \n         for (int i = 0; i < m; ++i) { \n            if (l[i] != -1) ans = min(ans, m-i-1); \n            if (r[i] != -1) ans = min(ans, i); \n        }\n\n        //does\'nt found any suffix return ans with respect to logest prefix found\n        if (r[m-1] == -1) return ans; \n\n        for(int i=0;i<m-1;i++){\n\n            //calculate longest suffix we can able to secure with respect to current index i prefix \n            if(l[i]!=-1){\n                if(l[i]>=r[m-1]){\n                    break;\n                }\n                int lo=i+1,hi=m-1;\n                int temp;\n                while(lo<=hi){\n                    int mi=lo+(hi-lo)/2;\n                    if(l[i]>=r[mi]){\n                        lo=mi+1;\n                    }\n                    else{\n                        temp=mi;\n                        hi=mi-1;\n                    }\n                }\n                ans=min(ans,temp-i-1);\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']