I tried merge sort.

and stable_sort() bt both gives TLE. plz help.links to my submission is given.

# TSORT- TLE.. i tried merge sort and sorting in algorithm header

**azimuthal**#1

**kcahdog**#2

Merge sort is a Comparison based sort and runs in O(n logn ) time. The question is designed in such a way that the counting Sort algorithm which is O(N) can be easily applied here.All numbers are between 0 and 1000000 so you can count the number of times each digit occurs and print it accordingly. I would suggest you look at a sample solution and read from Wikipedia about counting sort.

**kuruma**#3

I remember that for that problem I used the built-in heapsort() C++ function and got accepted

Also, afaik, sorting doesn’t need to be stable!

This was my accepted solution with heapsort():

In fact, experimenting pretty fast using the built-in sort() function, gets AC in even less time in C++:

Just for fun and training, I’ve also implemented my own version of heapsort in C and got AC as well:

Own implementation of Heapsort

Hope this helps,

Bruno