Solution: Largest Number
Explore how to solve the problem of forming the largest possible number by rearranging a list of non-negative integers. Understand the greedy strategy that involves custom comparison of concatenated strings to determine the optimal order. This lesson guides you through implementing a solution that sorts numbers based on which concatenation yields a larger value, and addresses special cases like lists of zeros.
We'll cover the following...
We'll cover the following...
Statement
Given a list of non-negative integers, nums, rearrange them so that they form the largest possible number. As the result may be very large, return it as a string.
Constraints:
nums.lengthnums[i]
Solution
At first glance, one might think sorting the numbers from largest to smallest would work, but that fails in cases like