EASY WINDOW MAKINS SOLUTION || IN DEPTH APPROACH .
Intuition\n Describe your first thoughts on how to solve this problem. \n\n- You have two strings s and t of the same length.\n- There\'s a cost associated with
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n- You have two strings `s` and `t` of the same length.\n- There\'s a cost associated with changing a character in `s` to the corresponding character in `t`. The cost is the absolute difference between their ASCII values.\n- The code finds the maximum length of a substring in `s` that can be transformed to the same substring in `t` with a total cost less than or equal to `maxCost`.\n\n**Nutshell:**\n\n- The code employs a sliding window approach with two pointers `i` and `j`. It keeps track of the current cost within the window and expands the window as long as the cost is within the limit. It shrinks the window from the left side if the cost exceeds the limit.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n\n\n\n**Steps:**\n\n1. **Initialization:**\n   - `int i = 0, j = 0, ans = 0;`: Initializes `i` and `j` as pointers to the beginning of both strings (`s` and `t`) and `ans` to store the maximum length found so far.\n\n2. **Sliding Window Loop:**\n   - `while (j < s.length()) {`: Continues the loop as long as the right pointer `j` is within the bounds of `s` (not reaching the end).\n     - **Expanding the Window:**\n       - `while (j < s.length() && maxCost >= 0) {`: This loop expands the window by incrementing `j` as long as the cost stays within the limit (`maxCost` is non-negative).\n         - `maxCost = maxCost - (Math.abs(s.charAt(j) - t.charAt(j)));`: Calculates the cost for including the character at index `j` in the window. It subtracts the absolute difference between the characters at `j` in `s` and `t` from the remaining `maxCost`.\n         - **Update Maximum Length:**\n           - `if (maxCost >= 0) {`: If the cost remains non-negative after including the character at `j`, it signifies a valid substring within the window.\n             - `ans = Math.max(ans, j - i + 1);`: Updates `ans` with the maximum length encountered so far. Here, `j - i + 1` represents the current window length.\n         - Increments `j` to move the right pointer and explore the next character.\n     - **Shrinking the Window (if Cost Exceeds Limit):**\n       - `while (maxCost < 0) {`: This loop shrinks the window from the left side (incrementing `i`) as long as the cost exceeds the limit (`maxCost` is negative).\n         - `maxCost = maxCost + (Math.abs(s.charAt(i) - t.charAt(i)));`: Calculates the cost for removing the character at index `i` from the window. It adds the absolute difference between the characters at `i` in `s` and `t` to the current `maxCost`.\n         - Increments `i` to move the left pointer and adjust the window.\n\n3. **Return Result:**\n   - After the loop exits, `ans` holds the maximum length of a valid substring found within the cost limit.\n   - `return ans;`: Returns the calculated maximum length.\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass Solution {\n    public int equalSubstring(String s, String t, int maxCost) {\n        int i=0;\n        int j=0;\n        int ans=0;\n        while(j<s.length()){\n            while(j<s.length() && maxCost>=0){\n                maxCost=maxCost-(Math.abs(s.charAt(j)-t.charAt(j)));\n                if(maxCost>=0){\n                    ans=Math.max(ans,j-i+1);\n                }\n                j++;\n            }\n            \n            while(maxCost<0){\n                maxCost=maxCost+(Math.abs(s.charAt(i)-t.charAt(i)));\n                i++;\n            }\n        }\n        return ans;\n    }\n}\n```
['Sliding Window', 'Java']