Sliding window & Two Pointers Pattern
\n# Code\n\n// Exact same as some problem add it for reference\nclass Solution {\n    public int equalSubstring(String s, String t, int maxCost) {\n\n        in
\n# Code\n```\n// Exact same as some problem add it for reference\nclass Solution {\n    public int equalSubstring(String s, String t, int maxCost) {\n\n        int maxLength=0,left=0,right=0;\n        int n=s.length();\n\n        while(right<n){\n\n            int diff = Math.abs(s.charAt(right)-t.charAt(right));\n            maxCost-=diff;\n            while(maxCost<0){\n                int leftDifference = Math.abs(s.charAt(left)-t.charAt(left));\n                maxCost+=leftDifference;\n                left++;\n            }\n            if(maxCost>=0) maxLength = Math.max(maxLength,right-left+1);\n            right++;\n        }\n        return maxLength;\n        \n    }\n}\n```
['Java']