Why is that I get answers when I run in my system but not in codechef?

Considering this example, I find no flaw here…

def sorting():
	holder=[]
	t=int(input())
	for i in range(t):
		n=int(input())
		holder.append(n)
	holder.sort()
	for i in holder:
		print i
        if __name__='__main__':
                sorting()

What’s wrong with this code? I get perfect results in my system but, not here.

this is the corrected code…

holder=[]
t=int(input())
for i in range(t):
	n=int(input())
	holder.append(n)
holder.sort()
for i in holder:
	print i

but it gives TLE…i think due to slow nature of input!!!

EDIT

also there is a faster algo that is possible…u do not nned to sort…it is a O(n) solution!!!

u can make an array of 10^6 cells and then store in them the count of each number that is given as input…for eg…the input is 1 2 3 4 5

then the array will be 0 1 1 1 1 1 0 0 0…

then just traverse the array and print that number that many number of times!!!

hope this helps!!!

1 Like
//