C++/Java Sliding Window O(n) | O(1)
Intuition\nInstead of two string, we can imagine an array of the same size with absolute differences. Then, the problem is to find the longest subarray with the
# Intuition\nInstead of two string, we can imagine an array of the same size with absolute differences. Then, the problem is to find the longest subarray with the sum not exceeding ```maxCost```.\n# Sliding Window\nWe can use a sliding window technique when we move right ```i``` pointer and decrease ```maxCost```, and increment left ```j``` pointer, increasing  ```maxCost``` if it is negative.\n\nThen, the difference ```i - j``` is our answer.\n### C++\n```\nint equalSubstring(string s, string t, int maxCost) {\n  auto i = 0, j = 0;\n  while (i < s.size()) {\n    maxCost -= abs(s[i] - t[i++]);\n    if (maxCost < 0) maxCost += abs(s[j] - t[j++]);\n  }\n  return i - j;\n}\n```\n### Java\n```\npublic int equalSubstring(String s, String t, int maxCost) {\n  int i = 0, j = 0;\n  while (i < s.length()) {\n    maxCost -= Math.abs(s.charAt(i) - t.charAt(i++));\n    if (maxCost < 0) maxCost += Math.abs(s.charAt(j) - t.charAt(j++));\n  }\n  return i - j;\n}\n```\n# Complexity Analysis\nTime: O(n)\nMemory: O(1)
[]