Easiest, Understandable C++ Solution with intuition, approach, complexities and code
Intuition\n Describe your first thoughts on how to solve this problem. \nAs question telling us to deal with costs as difference of ascii value of corresponding
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs question telling us to deal with costs as difference of ascii value of corresponding characters of s and t, so we will deal with that way only\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nnow first of all we will find cost of characters. lets say we have  abcd and acde for that  costs will be 0,1,1,1.\n\nas we can se a pattern that it is a problem of sliding window\nnow we will apply that method to find a subarray(substring) that best satisfy required condition of maxCost.\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 n=s.size();\n      \n          //abcd and acde\n        // 0,1,1,1   \n       int i=0, j=0, ans=0,sum=0;\n       while(j<n){\n\n        sum+=abs(int(s[j])-int (t[j]));\n\n        if(sum<=maxCost){\n            ans=max(j-i+1,ans);\n            \n        }\n\n        else {\n           while(sum>maxCost && i<=j){\n             sum= sum-abs(int(s[i])-int (t[i]));\n            i++;\n           }\n        }\n        j++;\n\n       }\n\n       return ans;       \n    }\n};\n```
['Sliding Window', 'C++']