Java Sliding Window with Clear Explanation
Explanation:\n\nThe idea is that you want to convert one character to another in that same position i.e. s[i] to t[i] such that you form the longest contiguous 
**Explanation:**\n\nThe idea is that you want to convert one character to another in that same position i.e. s[i] to t[i] such that you form the longest contiguous converted String.\n\nThere is just one key realization that you must make to solve this problem:\n\nYou need to realize that this problem can be reduced to finding the longest subarray such that the sum of the elements in that subarray is less than maxCost.\n\nThis is because you can generate an array `diff` such that `diff[i] = Math.abs(s[i] - t[i])` which is the cost of converting one character to another. You also want to find the maximum length substring that can be converted given the maxCost so this is equivalent to finding the longest subarray in `diff` which has sum of elements less than cost.\n\nFor this we can use a sliding window. We slide the `end` of the window to the right with each step. If the total sum exceeds the maxCost, we slide the `start` of the window to the right until the total sum inside the window is less than maxCosts. With each eligible window, we take the length and keep track of the maximum length.\n\nFor more info on sliding window: [Explanation](https://www.geeksforgeeks.org/window-sliding-technique/)\n\n**Code:**\n\n```\n\nclass Solution {\n    public int equalSubstring(String s, String t, int maxCost) {\n        // Convert the problem into a min subarray problem\n        int[] diff = new int[s.length()];\n        for(int i = 0; i < s.length(); ++i) {\n            int asciiS = s.charAt(i);\n            int asciiT = t.charAt(i);\n            diff[i] = Math.abs(asciiS - asciiT);\n        }\n        \n        // Now find the longest subarray <= maxCost\n        // all diff[i] >= 0 (non-negative)\n        \n        // Use sliding window?\n        int maxLen = 0;\n        int curCost = 0;\n        int start = 0;\n        \n        for(int end = 0; end < diff.length; ++end) {\n            curCost += diff[end];\n            while(curCost > maxCost) {\n                curCost -= diff[start];\n                ++start;\n            }\n            maxLen = Math.max(maxLen, end - start + 1);\n        }\n        \n        return maxLen;\n    }\n}\n```\n\n`Time Complexity: O(N) where N is the length of strings s, t`\n`Space Complexity: O(N) for diff`\nNote: O(1) space can be achieved if we don\'t create the diff array - we can just get the values on the fly.
['Java']