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

8

u/cresquin May 08 '15 edited May 08 '15
  • sort by first digit into arrays (backwards)

    [991, 993, 9913][55][2]

  • within each first digit array, sort by second digit into arrays

    [[991, 993, 9913]][[55]][[2]]

  • continue to recurse to longest number length

    [[993, [991, [9913]]]][[55]][2]

  • flatten

    [993, 991, 9913, 55, 2]

  • join

    parseInt([993,991,9913,55,2].join(""));

5

u/[deleted] May 08 '15

How do you sort when a digit is missing? For example:

[34, 3, 32]

2

u/compiling May 08 '15

Treat it as the first digit.

4

u/rabbitlion May 08 '15

How does that solve the issue`?

→ More replies (0)