FunctionRacerProblemsRace

Smallest Joined Number

MediumGreedyPython, JavaScript, TypeScript, Java, C++

nums is a list of positive integers. Write them one after another, in an order of your choice and without separators, to form one long string of digits; every item is used exactly once.

Return the smallest string that can be formed, where strings are compared as numbers (all orders give the same length, so this is the usual string comparison). The result may be too long for an integer, so return it as a string. The smallest string is unique, so no tie rule is needed. Return the empty string for an empty list.

Example 1

nums [3,30,34,5,9]
returns "3033459"

30 goes before 3 because 303 beats 330; after that 34, 5 and 9 follow in order.

Example 2

nums [10,2]
returns "102"

102 beats 210, so 10 goes first.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Greedy problems