Given a list of non-negative integers, arrange them so that writing them one after another forms the largest possible number. Write largest_number(nums) that returns that number as a string (it can be far too long for an int).
1 <= len(nums) <= 10,000; each value is in[0, 10^9].- No leading zeros in the answer: if every value is
0, return"0", not"000".
Sorting the values as strings in descending order is not enough: [3, 30] must give "330", not "303". Aim for O(n log n) comparisons.
largest_number([30, 3, 34, 5, 9]) # "9534330"
largest_number([0, 0]) # "0"
largest_number([121, 12]) # "12121"
largest_number([3, 30]) # "330"
Show hint
you only ever need to decide which of two numbers should come first. Try both orders of the pair and see which gives the bigger string, then sort with that comparison.