Simple Two Pointer Approach!!
Complexity\n- Time complexity: 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 equ
# Complexity\n- Time complexity: 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 left = 0; //to keep track of the first element in every substring\n        int right = 0; // to keep track of current element\n        int maxLen = 0;\n        int n = s.size();\n        int cost = 0;\n        while(right < n){\n            cost += abs((s[right] - \'0\') - (t[right] - \'0\'));\n            while(cost > maxCost){ //if cost exceeds shrink the window\n                cost -= abs((s[left] - \'0\') - (t[left] - \'0\'));\n                left++;\n            }\n            maxLen = max(maxLen, right - left + 1); //update maxLen\n            right++;\n        }\n        return maxLen;\n    }\n};\n```
['Array', 'Two Pointers', 'Sliding Window', 'C++']