in reply to Re: Sorting challenge (Insertion sort)
in thread Sorting challenge
This is an excellent approach, but there are two potential issues with the specific solution. In other words, the algorithm is great, but the implementation is not quite there yet. One issue is that the test harness is probably happily supplying an infinite stream of integers, or at least more of them than are specified in the first input. If time limit is exceeded, I would guess that the stream just keeps going.
The second issue is that there could be, and probably are, integers that show up multiple times in the input stream. They would be lost here. So modifying Buk's solution:
chomp( my $count = <> ); my @numbers; $numbers[scalar <>]++ while $count--; foreach my $number ( 0 .. $#numbers ) { next unless defined $numbers[$number]; print "$number\n" for 1 .. $numbers[$number]; }
If that exceeds the time limitation, I'm with BrowserUk; they're nuts; this is an O(n) solution. ;)
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Sorting challenge (Insertion sort)
by BrowserUk (Patriarch) on Jul 23, 2013 at 19:57 UTC | |
by PerlSufi (Friar) on Jul 23, 2013 at 20:06 UTC | |
by davido (Cardinal) on Jul 24, 2013 at 00:12 UTC | |
|
Re^3: Sorting challenge (Insertion sort)
by BrowserUk (Patriarch) on Jul 24, 2013 at 12:02 UTC | |
by davido (Cardinal) on Jul 24, 2013 at 14:20 UTC | |
by BrowserUk (Patriarch) on Jul 24, 2013 at 14:35 UTC | |
by davido (Cardinal) on Jul 24, 2013 at 22:27 UTC | |
by BrowserUk (Patriarch) on Jul 24, 2013 at 22:48 UTC | |
by choroba (Cardinal) on Jul 24, 2013 at 15:00 UTC | |
by BrowserUk (Patriarch) on Jul 24, 2013 at 15:17 UTC | |
|
Re^3: Sorting challenge (Insertion sort)
by PerlSufi (Friar) on Jul 23, 2013 at 19:57 UTC | |
|
Re^3: Sorting challenge (Insertion sort)
by hdb (Monsignor) on Jul 23, 2013 at 19:39 UTC |