Description
You are given two strings s and t of the same length and an integer maxCost. You want to change s to t. The cost of changing s[i] to t[i] is |s[i] - t[i]|. Return the maximum length of a substring that can be changed with cost at most maxCost.
Examples
Input:
s = "abcd", t = "bcdf", maxCost = 3Output:
3Explanation:
abc -> bcd costs 3.
Input:
s = "a", t = "a", maxCost = 3Output:
0Explanation:
Edge case with a single character.
Input:
s = "abcdef", t = "aecdhf", maxCost = 4Output:
4Explanation:
The costs for each position are: |a-a|=0, |b-e|=3, |c-c|=0, |d-d|=0, |e-h|=3, |f-f|=0. It is possible to choose substring "bcde" (positions 1-4) with total cost 3+0+0+3=6, but this exceeds maxCost. The optimal substring is "abcd" (positions 0-3) with cost 0+3+0+0=3, giving us length 4.
Constraints
- •
1 ≤ s.length ≤ 10^5 - •
s.length == t.length