Something like this:
public static int findLength(String str, int k) {
if(str == null || str.isEmpty() || k <= 0) {
return -1;
}
int res = 0;
int start = 0;
int end = 0;
int skip = k;
while(start <= end && end < str.length()) {
if(str.charAt(start) == str.charAt(end) || skip > 0) {
if(str.charAt(start) != str.charAt(end)) {
skip--;
}
end++;
}
else {
res = Math.max(res, end - start);
skip++;
start++;
}
}
return Math.max(res, end - start);
}
Type your question above this line.
Course: https://www.educative.io/collection/5668639101419520/5671464854355968
Lesson: https://www.educative.io/collection/page/5668639101419520/5671464854355968/6497958910492672