Sliding window  ||  Java  ||  Easy  ||  🚀🚀  ||  🔥🔥
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int equalSubstring(String s, String t, int maxCost) {
        int n = s.length();
        int l = 0;
        int r=  0;

        int cost = 0;
        int ans =0;

        while(r<n){
            int a = s.charAt(r);
            int b = t.charAt(r);

            cost += Math.abs(a-b);

            while(cost>maxCost){
                cost -= Math.abs(s.charAt(l) - t.charAt(l));
                l++;
            }

            ans = Math.max(ans,r-l+1);
            r++;
        }

        return ans;
    }
}
```
['Java']