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

1

u/DerJawsh May 08 '15

I think that can be solved by making it so we only take the shorter number if the next digit of the larger number is smaller than the first digit of the shorter number.

2

u/jcdyer3 May 08 '15

Alternatively, to keep the sorting logic simpler, I think you could sort each number with digits ABC..N by the key ABC..NA.

In python:

ints = sorted(ints, key=lambda x: str(x) + str(x)[0])