getting tle: your name is mine

i tried to optimize my code but it still gives tle

can anyone please help.

my code: http://www.codechef.com/viewsolution/3790848

problem: http://www.codechef.com/problems/NAME2

Your code is giving WA bacause of this part:

for(m=0;m<strlen(b);m++)
{  for(;j<=k;j++)
   {   if(b[m]==a[j])
       {  c++;break;}
   }
}

See this

You approach is giving TLE as you are using strlen() function in the for loop as breaking condition.
If you will use

 `for(i=0;b[i]!='\0';i++)`     

then your code will not give TLE. strlen() takes O(n) time to calculate the length of the string. So using strlen() made your code O(n^2).

2 Likes
//