in reply to Re^5: Sorting challenge
in thread Sorting challenge

Wow, nice davido. However, all of those still gave 'time limit exceeded'. Actually, all of the responses here did. Though they were all far better than my attempt! Here is the link explaining this message from the site:
http://www.codechef.com/wiki/faq#Why_do_I_get_a_Time_Limit_Exceeded

Replies are listed 'Best First'.
Re^7: Sorting challenge
by davido (Cardinal) on Jul 23, 2013 at 16:00 UTC

    The incoming list is potentially 10^6 integers long, correct? That's potentially 1_000_000 integers.

    This can be solved, it may involve packing your input into a huge string using pack, appending each int's packed representation onto the same string. Then manually implementing a sort that works in-place within the string, again using pack and unpack.

    Messy! I don't think I want to invest the time in it. :)

    Updated to correct math. ;)

    Actually, 1 million integers in an array shouldn't be a deal-breaker, unless they're severely limiting your memory. My while-loop solution ought to be the most memory friendly. The map solutions generate a list of 1 .. n before sorting the inputs, so you're holding 2M integers rather than 1M in memory.


    Dave