Easy Sliding Window
Intuition\n Describe your first thoughts on how to solve this problem. \nsliding window\n\n# Approach\n Describe your approach to solving the problem. keep addi
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nsliding window\n\n# Approach\n<!-- Describe your approach to solving the problem. -->keep adding the current difference value until it is less then max value once it cross , then increse the previous pointer till it is less then max value and in each iteration take out the maximum result\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\n\n\n\nPLEASE UPVOTE MY SOLUTION\n\n# Code\n```\nclass Solution {\n    public int equalSubstring(String s, String t, int maxCost) {\n        int n = s.length();\n        int start = 0;\n        int currentCost = 0;\n        int maxLength = 0;\n\n        for (int end = 0; end < n; ++end) {\n            currentCost += Math.abs(s.charAt(end) - t.charAt(end));\n\n            while (currentCost > maxCost) {\n                currentCost -= Math.abs(s.charAt(start) - t.charAt(start));\n                ++start;\n            }\n\n            maxLength = Math.max(maxLength, end - start + 1);\n        }\n\n        return maxLength;\n    }\n}\n```
['Java']