Lets try to simplify the problem and try to solve it for one letter('A'). To solve that problem we can use two pointers. Each time we will try to move our right pointer. We can move it in two cases:

- if the s[right]=='A'
- if the s[right]!='A' and there is enough K to replace the character with 'A';

We will move left if there isn't anymore K to replace any character at position [right].

Each time we should track the number of replacements we did. When we move left we need to decrease using number of replacements if s[left]!='A';

The answer will be range between left and right;

If we will solve this problem for each letter then we can find maximum amoung their maximum length's

```
public class Solution {
public int characterReplacement(String s, int k) {
int max = 0;
for (char i='A'; i<='Z'; i++) {
int L = 0;
int R = 0;
int cnt = 0;
while (R<s.length()) {
if (s.charAt(R)==i) {
R++;
} else {
if (cnt<k) {
R++;
cnt++;
} else {
if (s.charAt(L)!=i) {
cnt--;
}
L++;
}
}
max = Math.max(max, R-L);
}
}
return max;
}
}
```