Very Easy to Understand Python Solution (Sliding Window Approach)
Approach
💡 Approach: Sliding Window
We use the sliding window technique to efficiently find the longest substring that can be modified within the given cost.
St
# Approach
- 💡 **Approach: Sliding Window**
We use the sliding window technique to efficiently find the longest substring that can be modified within the given cost.

**Steps:**
- Calculate the Cost Array:
Compute the difference in ASCII values for corresponding characters of s and t to form the cost array.

**Sliding Window Logic:**
1) Maintain two pointers: left (start of the window) and right (end of the window).
2) Expand the window by incrementing right and adding cost[right] to the current_cost.
3) If current_cost exceeds maxCost, shrink the window by incrementing left and subtracting cost[left] from current_cost.

**Track Maximum Length:**
Keep updating the maximum length of the valid substring (right - left + 1) during the process.


# Complexity
# - Time complexity:
**Cost Calculation:** O(n), where n is the length of the string.
**Sliding Window Traversal:** O(n), as both left and right pointers traverse the string at most once.
**Total:** O(n).
# - Space complexity:
**Cost Array:** O(n) to store the absolute differences.
**Total:** O(n).

# Code
```python3 []
class Solution:
    def equalSubstring(self, s: str, t: str, maxCost: int) -> int:
        cost= [abs(ord(s[i]) - ord(t[i])) for i in range(len(s))]

        i = 0
        curr_cst = 0
        max_len = 0

        for j in range(len(s)):
            curr_cst += cost[j]

            if curr_cst > maxCost:
                curr_cst -= cost[i]
                i+=1
            max_len = max(max_len, j-i+1)
        return max_len
```
['Python3']