Time limit exceeded problem

import java.io.*;
class princess
{
public static void main(String[] args)
{
try {
String s="",rev="",sub="",cs="";
int k=0,i,l,j,T=0,flag=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//System.out.println(“enter no. of test cases”);
cs=br.readLine();
T=Integer.parseInt(cs);
String result[]=new String[T];
for(k=0;k<T;k++)
{
//System.out.println(“enter the string”);
s=br.readLine();
for(l=0;l<s.length()-1;l++)
{
for(i=l+2;i<s.length()+1;i++)
{
sub=s.substring(l,i);
for(j=sub.length()-1;j>=0;j–)
{
rev=rev+sub.charAt(j);
}
if(rev.equals(sub))
{
flag=1;
break;
}
rev="";
}
if(flag==1)
break;
}

    if(flag==1)
    result[k]="YES";
    else
    result[k]="NO";
    flag=0;
    }//outter most loop end
    

    for(k=0;k<T;k++)
    {
         System.out.println(result[k]);
    }
                 }//try block end

catch(Exception e){
return;
}
}
}

Question-https://www.codechef.com/LOCAUG17/problems/PRINCESS

Problem-Time limit exceeded

You can not ask a question related to live contest!!

Please Wait for the contest to end.

@vijju123 please close this question