---
title: "1208. Get Equal Substrings Within Budget"
url: "https://laigary.com/interview/coding/1208-get-equal-substrings-within-budget"
type: "note"
section: "coding"
date: "2025-03-24"
updated: "2025-03-24"
tags: ["Sliding Window"]
---

# 1208. Get Equal Substrings Within Budget

[1208\. Get Equal Substrings Within Budget](https://leetcode.com/problems/get-equal-substrings-within-budget/)

```python
class Solution:
    def equalSubstring(self, s: str, t: str, maxCost: int) -> int:
        maxLen = 0
        currCost = 0
        start = 0

        for i in range(len(s)):
            currCost += abs(ord(s[i]) - ord(t[i]))

            while currCost > maxCost:
                currCost -= abs(ord(s[start]) - ord(t[start]))
                start += 1
            
            maxLen = max(maxLen, i - start + 1)
        
        return maxLen
```
