r/programming • • 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.1k comments sorted by

View all comments

Show parent comments

3

u/MSgtGunny May 08 '15 edited May 08 '15

I would sort based on first digit of each number, if there is a conflict, it checks the next digit of both or next digit of one and the current digit if there are no more digits for the number.

Ie 5 53 55 59 501 would be sorted as 59, 55, 5, 53, 501

Maybe a modified radix sort would do the job.

2

u/Weezy1 May 08 '15

You've described an alphabetic String sort :)

1

u/MSgtGunny May 08 '15

Sort of, except a purely alphabetic string sort would've produced 59, 55, 53, 501, 5 Which is non optimal.

1

u/[deleted] May 08 '15

What if you found the longest number, expanded other numbers with some character that sorts higher(in case of reverse lower) than 0. And then just sorted it, concated it and stripped the character...