Sliding Window Solution || JAVA ;)
\n\n# Code\n\nclass Solution {\n    public int equalSubstring(String s, String t, int maxCost) {\n        int maxLen =0;\n        int n = s.length();\n        i
\n\n# Code\n```\nclass Solution {\n    public int equalSubstring(String s, String t, int maxCost) {\n        int maxLen =0;\n        int n = s.length();\n        int j=0;\n        int currCost=0;\n\n        for(int i=0; i<n; i++){\n            //getting elemnts from the window\n            char c1 = s.charAt(i);\n            char c2 = t.charAt(i);\n            currCost += getCost(c1,c2);\n            while(maxCost < currCost){\n                //removing elements from the window\n                char c3 = s.charAt(j);\n                char c4 = t.charAt(j);\n                int costReduce = getCost(c3, c4);\n                currCost -= costReduce;\n                j++;\n            }\n            maxLen = Math.max(maxLen, i-j+1);\n        }\n        return maxLen;\n    }\n    private int getCost(char c1, char c2){\n        int val1 = c1-\'a\';\n        int val2 = c2-\'a\';\n        int ans = val1-val2;\n        return Math.abs(ans);\n    }\n}\n```
['Java']