Simple Solution using Sliding Window - Beats 100% T.C O(N)
Intuition\n Describe your first thoughts on how to solve this problem. \nWe want to find the longest substring in s such that changing it to match t costs no mo
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe want to find the longest substring in s such that changing it to match t costs no more than maxCost. The cost of changing a character `s[i]` to `t[i]` is the absolute difference `abs(s[i] - t[i])`\n\n# Sliding Window Approach\n<!-- Describe your approach to solving the problem. -->\n1. Imagine you have a window that starts at the beginning of the string s.\n1. You keep expanding this window to include more characters until the total cost of changes exceeds maxCost.\n1. If the cost becomes too high, you start moving the start of the window forward to reduce the cost.\n1. Throughout this process, you keep track of the maximum length of any valid window (substring) found.\n\n- `j` to mark the start of the current window.\n- `count` to count the number of characters in the current window.\n- `sum` to keep track of the total cost of converting the current window.\n- `maxcount` to store the maximum length of a valid window found.\n\n# Complexity\n- Time complexity:$$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int equalSubstring(string s, string t, int maxCost) {\n        int j = 0, count = 0,sum = 0, maxcount = 0;\n        for(int i=0;i<s.size();i++)\n        {\n            sum+=abs(s[i]-t[i]);\n            count++;\n            while(sum>maxCost && j<s.size())\n            {\n                sum-=abs(s[j]-t[j]);\n                count--;\n                j++;\n            }\n            maxcount = max(maxcount,count);\n        }\n        return maxcount;\n    }\n};\n```
['Two Pointers', 'String', 'Sliding Window', 'Prefix Sum', 'C++']