Sanket and Strings Problem

https://ide.geeksforgeeks.org/gDsI5TiuFh---output is not correct what’s the error in my code?

String str = cin.nextLine();// here use cin.next()

next() can read the input only till the space. It can’t read two words separated by space. Also, next() places the cursor in the same line after reading the input. nextLine() reads input including space between the words (that is, it reads till the end of line n).

logic is not correct.
Make two variabes , say i and j .
i defines the beginning of a window and j defines its end.
Start i from 0 and j from k.
Let’s talk about the singular case when we are considering the max window for only 'a’s and consider only the swapping of b-> a. If we are able to get the answer for max window of consecutive 'a’s , we can simply implement the same algo for the max ‘b’ window as well.
So we started i from 0 and j from k.
Move j ahead freely as long as there are ‘a’ characters at s[ j ] position.

Maintain a count variable which counts the number of swaps made or the number of 'b’s in our A window.

If you encounter a ‘b’ char at s[ j ] position , increment the count variable. Count should never exceed k .
Take the size of the window at every point using length = j - i + 1;
Compute the max size window this way and do the same for ‘b’ as well.
Output the maximum size window of ‘a’ and ‘b’.

i have made the changes u told but with slight changes what are error there in this approach, can u please make the corrections because 2 test cases out of three are not passing----https://ide.geeksforgeeks.org/xxrdyFvjT2

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int swaps = cin.nextInt();
String str = cin.next();
int res = Math.max(findLen(str, ‘a’, swaps), findLen(str, ‘b’, swaps));
System.out.println(res);
}
public static int findLen(String str,char ch,int k ){
int max = 1;
int l = 0;
int r = 0;
int count = 0;
while (r < str.length()) {
if (str.charAt® != ch)
count++;
while (count > k) {
if (str.charAt(l) != ch)
count–;
l++;
}
max = Math.max(max, r - l + 1);
r++;
}
return max;

}
}