You are not logged in. Please login at www.codechef.com to post your questions!

×

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++) <br=""/> {
//System.out.println("enter the string");
s=br.readLine();
for(l=0;l<s.length()-1;l++) <br=""/> {
for(i=l+2;i<s.length()+1;i++)<br/> {
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

asked 28 Aug '17, 01:06

oggyiesanmol's gravatar image

2★oggyiesanmol
-11
accept rate: 0%

edited 28 Aug '17, 01:10


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

Please Wait for the contest to end.

@vijju123 please close this question

link

answered 28 Aug '17, 09:10

kunnu120's gravatar image

2★kunnu120
5189
accept rate: 5%

edited 28 Aug '17, 09:11

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,313
×205
×38

question asked: 28 Aug '17, 01:06

question was seen: 195 times

last updated: 28 Aug '17, 09:11