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
2
u/Inondle May 08 '15
Number 4 was 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 get the first digit. (I converted to string and got first character)
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.
In theory that should get the correct answer. Only reason I thought of that was I saw radix sort on this algorithm site and it blew my mind you could sort with no comparisons.