i tried to optimize my code but it still gives tle
can anyone please help.
i tried to optimize my code but it still gives tle
can anyone please help.
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;}
}
}
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).