Beats 100% users🔥 |  Approach explained✅ | Well-commented code
Approach\n- Use two pointers (start and end) to represent the current window.\n- Expand the window by moving the end pointer and calculate the cost of transform
# Approach\n- Use two pointers (start and end) to represent the current window.\n- Expand the window by moving the end pointer and calculate the cost of transforming the substring `s[start:end]`into `t[start:end]`.\n- If the total cost exceeds maxCost, shrink the window by moving the start pointer and reducing the cost accordingly.\n- Track the maximum length of a valid substring during the process.\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int equalSubstring(string s, string t, int maxCost) {\n        int start = 0; // Left pointer for the sliding window\n        int cost = 0;  // Current transformation cost\n        int len = 0;   // Maximum length of a valid substring\n\n        for (int end = 0; end < s.size(); end++) {\n            // Add the transformation cost for the current character\n            cost += abs(s[end] - t[end]);\n\n            // Shrink the window if the cost exceeds maxCost\n            while (cost > maxCost) {\n                cost -= abs(s[start] - t[start]); // Reduce cost\n                start++;                          // Move the start pointer\n            }\n\n            // Update the maximum length of the valid substring\n            len = max(len, end - start + 1);\n        }\n\n        return len;\n    }\n};\n```
['String', 'Sliding Window', 'C++']