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
0
u/roselan May 08 '15
my first idea was to pad all numbers to the lengthiest one with 0s, sort them, and remove the 0s before appending.
but then you would have:
5 50 563 -> 500 500 563
huh? which 500 is the biggest one? so let's be ""smart"" and add the length as decimal for sorting:
5 50 563 -> 500.1 500.2 563.3
but then we run into a bug. 50 > 5, which is wrong. So use a (maxlength - length) as decimal:
5 50 563 -> 500.2 500.1 563.0
Sort it descending, and I have a job =]
(yeah i know create an map with a proper index instead of this decimal thingy, yadayada...)