Simple and easy solution with comments ✅✅
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# Co
# 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\n    // Method 1 - Sliding window\n    // TC = O(N), SC = O(1)\n    int equalSubstring(string s, string t, int maxCost) {\n        int ans = 0, i = 0, j = 0, n = s.length(), diff = 0;\n\n        while(j < n){\n            // calculate difference\n            diff = diff + abs(s[j] - t[j]);\n\n            // if diff <= maxCost then store ans\n            if(diff <= maxCost){\n                ans = max(ans, (j-i+1));\n                j++;\n            }\n            // else increment i till diff > maxCost\n            else{\n                while(diff > maxCost){\n                    diff = diff - abs(s[i] - t[i]);\n                    i++;\n                }\n                j++;\n            }\n        }\n\n        return ans;\n    }\n};\n```
['C++']