LUCKY LETTERS from codeEra

this code is running perfect for all sample inputs as well other inputs too.yet shown wrong answer. can somebody help me to find the bug in this logic please?

import java.io.*;
class rkloves
{
int countR(String str,int m,int n)
{
int count=0;
for(int i=0;i<str.length();i++)
{
if(!(i>=m&&i<=m+n-1))
{
if(str.charAt(i)==‘R’)
{
count++;
}
}
}
return(count);
}

void countK(String str)
{
String substr=“”;
int no_R,no_K,p;
int max=0;
for(int i=0;i<str.length();i++)
{
for(int j=1;j<=str.length()-i;j++)
{
substr=str.substring(i,i+j);
no_R=0;
no_K=0;
p=0;
for(int k=0;k<substr.length();k++)
{
if(substr.charAt(k)==‘K’)
{
no_K++;
}
else
{
no_R++;
}}
p=countR(str,i,j);
if(no_K-no_R+p>=max)
{
max=no_K+p;
}
}
}
System.out.println(max);

}
public static void main(String args[])throws Exception
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
rkloves ob=new rkloves();
int t;
String str;
t=Integer.parseInt(in.readLine());
for(int i=1;i<=t;i++)
{
str=in.readLine();
ob.countK(str);
}
}
}