r/programming • u/svpino • May 08 '15
Five programming problems every Software Engineer should be able to solve in less than 1 hour
https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
2.5k
Upvotes
4
u/Inondle May 08 '15
Number 4 was fun and a little tricky. I decided to tackle it with a radix-style sort.
Load a hashMap<Integer, List<Integer>> with 1-9 keys and their respective lists.
Then take each number you're trying to sort and convert it to a string, take the first digit.
map.get(digit), add number to that list, then sort the list from highest to lowest.
After you're done with all the original numbers, go through each map entry (9->1) and take all the values from the entries' list and put it in a bigger list. return bigger list. Done :)