[C++/Python] | Sliding window
C++\n\nclass Solution {\npublic:\n    int equalSubstring(string s, string t, int maxCost) {\n        int ans = 0, c = maxCost, i = 0, j = 0;\n\n        for(int 
# C++\n```\nclass Solution {\npublic:\n    int equalSubstring(string s, string t, int maxCost) {\n        int ans = 0, c = maxCost, i = 0, j = 0;\n\n        for(int j=0; j<s.size(); j++) {\n            c -= abs(s[j] - t[j]);\n            if(c >= 0) ans = max(ans, j - i + 1);\n            else c += abs(s[i] - t[i]), i++;\n        }\n        return ans;\n    }\n};\n```\n\n# Python\n```\nclass Solution(object):\n    def equalSubstring(self, s, t, maxCost):\n        ans, i, c = 0, 0, maxCost\n\n        for j in range(len(s)):\n            c -= abs(ord(s[j]) - ord(t[j]))\n            if c >= 0: ans = max(ans, j - i + 1)\n            else:\n                c +=  abs(ord(s[i]) - ord(t[i]))\n                i += 1\n        \n        return ans\n```\n
['Sliding Window', 'Python', 'C++']