Here is my code :
import java.util.*;
public class Main {
public static int for_char (String A, char a) {
int maxlen = 1;
int count = 0;
int left = 0;
int right = 0;
while (right < A.length()) {
if (A.charAt(right) != a) {
count++;
}
while (count > 2) {
if (A.charAt(left) != a) {
count--;
}
left++;
}
maxlen = Math.max(maxlen, right - left + 1);
right++;
}
return maxlen;
}
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
String ss = s.next();
int max = 1;
max = Math.max(max, for_char(ss, 'a'));
max = Math.max(max, for_char(ss, 'b'));
System.out.println(max);
}
}
Please tell me where am I going wrong.