turbo sort TLE

hey i’m getting tle (time limit exceeded) for the following code the problem is http://www.codechef.com/problems/TSORT/

itr = int(raw_input())
arr = []
for i in xrange(0,itr):
	inp = int(raw_input())
for i in xrange(0,itr):
	print arr[i]

im not getting the problem in it pls help…


The i/p o/p speed of python is not great combined that with you using the sort function with an average time complexity of nlogn. Maybe the nlogn implementation can work in c/c++ with faster i/p & o/p but not in this implementation of python at least. Try reading about counting sort.

Hope that helps :slight_smile:

1 Like

actually this qus requires O(n) sorting algorithm, take a look at the constraints for N, you can use count sort :slight_smile: