Getting TLE in Chef and String

My solution is running on linear time but even after i am getting TLE.

For loop of test cases you have given condition while(t–) but it should be while(t–>0).

If you are saying while loop is not terminating then you are wrong because i always use this while loop for testcase and it always works.

Use substr() @stream_cipher

But substr also runs in linear time see these posts link1,link2

I think it is O(1) of substring and I got ac after doing it.

your approach isn’t efficient.
it’s simple:
string with odd length has only one type of character
string with even length: for all i, a[i] must be equal to a[i+2].
Read this and you will understand that the complexity of your code is not linear.

bro use append function to find l and r. The time complexity would be O(1) for every string.

naive approach -> define 2 strings , 1st one being left-rotation of the original , 2nd being the right-rotation , if they are equal , print yes

	for _ in range(int(input())):
		if sl==sr:

okay got it thanks :slight_smile: