Hi Aman! Here I have both binary search and two pointers methods. Idea is the same, great people think similar:=)

public class Solution {
public int characterReplacement(String s, int k) {
if(k>=s.length()) return s.length();
int res = k;
char w[] = s.toCharArray();
for(char cur = 'A';cur<='Z';cur++){
res = Math.max(res, findMax2Ptr(cur, w, k));
}
return res;
}
private int findMax2Ptr(char ch, char [] w, int k){
int res = 0;
int i = 0, j = 0;
while(j<w.length ){
if(ch == w[j]){
j++;
res = Math.max(res, j-i);
continue;
}
if(k == 0){
if(w[i] != ch){
k++;
}
i++;
} else {
k--;
j++;
}
res = Math.max(res, j-i);
}
return Math.max(res, j-i);
}
private int findMaxBinary(char ch, char [] w, int k){
int l = 0;
int r = w.length;
int res = 0;
while(l<=r){
int m = (l+r)/2;
if(countMinGaps(w, m, ch) <= k){
res = m;
l = m+1;
} else {
r = m-1;
}
}
return res;
}
private int countMinGaps(char w[], int size, char ch){
int count = 0;
int i = 0;
int res = size;
while(i<w.length){
if(i<size){
if(w[i] !=ch) {
count++;
}
} else {
res = Math.min(res, count);
if(w[i-size] != ch){
count--;
}
if(w[i] != ch) {
count++;
}
}
i++;
}
return Math.min(count,res);
}
}