Why I get unaccepted TLE?

I don’t see any reason to get TLE in this problem. Can someone please clarify to me why I am getting TLE?
Problem link:https://www.codechef.com/problems/TSORT
My solution link:https://www.codechef.com/viewsolution/29793300

this is a better way to do this…i feel
https://www.codechef.com/viewsolution/29793662
refer here :slight_smile:
append() function takes O(1) time, adding a list using assignment operation is slower

no wait i am wrong

1 Like

but essentially, append() function is safer.

1 Like

But what’s wrong with my code. That way should be work.

got it.
You are printing the whole solution in one line
So see, you need to match your answer with output.
Judge was still waiting for the test case to finish running
like you printed only one line.
but it had 5 lines for example and since you didn’t print it in the time needed, you got TLE.
if you print them in line it will work

2 Likes

Output:

1
3
5
6
7
So, you mean the output should be look like this. So, if I change my code for it, I think I should get AC. what change should I do now? using append?

1 Like

okay if you see my submission history…
I would say omg…this was very unique and undefined behaviour from python.
But also (https://www.codechef.com/viewsolution/29793792)

a=a+[n]

is a reason for TLE too (https://www.codechef.com/viewsolution/29793814)
the time limits are tight and this is actually slower…

a+=[n]

is faster.
Now i don’t remember the exact reason why but it’s easier for compiler to perform this than the assignment operation. :slight_smile:
But my recommendation is use append() function and i don’t see any difference between sorted() and sort() function

1 Like

it worked. thanks

1 Like

read all my messages you will understand where all it is different.
It’s important for your answer to match the output always.
but that wasn’t the reason and i was wrong a bit in my previous but your solution got TLE because of what i stated above

1 Like