i
and j
to 0
to represent the start and end of the sliding window, respectively.cost
to 0
to keep track of the current cost of changing the substring.s
using the j
pointer.
a. Calculate the cost of changing s[j]
to t[j]
and add it to cost
.
b. While cost
is greater than maxCost
, subtract the cost of changing s[i]
to t[i]
from cost
and increment i
to shrink the window.
c. Update the result with the maximum length of the window so far, which is j - i + 1
.