Arrange non-negative integers so their concatenation forms the largest possible number.
Given an array of non-negative integers, reorder the numbers so that when their decimal representations are concatenated, they form the largest possible integer-like string.
Your task is to return that maximum concatenation as a string.
Because the result may exceed standard integer limits, the answer must be handled as text rather than a numeric type.
Input Format
- An integer array
numsof non-negative integers. - Each element should be treated as its base-10 string representation during ordering.
Output Format
- Return a string representing the largest possible concatenation of all numbers in
nums.
Constraints
1 <= nums.length0 <= nums[i]- The final answer should not contain unnecessary leading zeros unless the result is exactly
"0".
Example 1
Input
[10,2]
Output
"210"
Explanation
Comparing "10" and "2": placing "2" before "10" gives "210", which is larger than "102".
Example 2
Input
[3,30,34,5,9]
Output
"9534330"
Explanation
A best ordering is [9, 5, 34, 3, 30], which concatenates to 9534330.
Show 1 more example
Example 3
Input
[0,0]
Output
"0"
Explanation
All concatenations start with zeros, so the normalized answer is just 0.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.