C++ | Sliding Window | Template | Easy
Do upvote if it helps! :)\n\nclass Solution {\npublic:\n    int equalSubstring(string s, string t, int maxCost) {\n       int n=s.size();\n       vector<int>dif
**Do upvote if it helps! :)**\n```\nclass Solution {\npublic:\n    int equalSubstring(string s, string t, int maxCost) {\n       int n=s.size();\n       vector<int>diff(n,0);\n        for(int i=0;i<n;i++){\n            diff[i]=abs((s[i]-\'a\')-(t[i]-\'a\'));\n        }\n        int res=0,left=0,k=maxCost,sum=0;\n        for(int i=0;i<n;i++){\n            sum+=diff[i];\n            if(sum>k){\n                sum-=diff[left];\n                left++;\n            }\n            res=max(res,i-left+1);\n        }\n        return res;\n    }\n};\n```
['C', 'Sliding Window']