Gamified challenge · Counting sort
Every letter in the sack has a postcode: an integer from 0 to 999. codes lists them in the order they fell out of the sack, with repeats.
Write sortMail(codes) that returns the postcodes sorted from smallest to largest, repeats included. Postcodes are small, so use counting sort: count how many letters go to each postcode, then write each postcode out that many times. That's O(n + k) for n letters and k possible postcodes.
Example: [42, 17, 42, 3, 25, 17] → [3, 17, 17, 25, 42, 42].
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google