Smallest Number From Digit Cards
cards lists digits from 0 to 9, one per card. Lay all the cards in a row to form the smallest possible number whose first digit is not 0. At least one card is not 0, so such a row always exists.
Return the number as a string of digits that uses every card exactly once. The smallest number is unique, so no tie rule is needed.
Example 1
cards [3,0,1,0,2]
returns "10023"
Sorted, the cards read 0, 0, 1, 2, 3; the smallest nonzero digit, 1, has to lead, and the zeros come right after it.
Example 2
cards [0,0,7]
returns "700"
With two zeros and a 7 the only row that does not start with 0 is 700.
Constraints
1 <= len(cards) <= 600 <= cards[i] <= 9- At least one card is not 0
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.