Form the Maximum Number from Array Elements
Problem Given an array of non-negative integers, arrange them so that concatenating their decimal representations forms the largest possible number.
Input / Output
- Input: array
numsof non-negative integers. - Output: the largest concatenation, returned as a string (it can exceed 64-bit range).
Constraints
- Up to ~10^4 elements, each with varying digit length.
- Values are non-negative; the result must be returned as a string since the concatenation may be far larger than any integer type.
Example
- Input:
[3, 30, 34, 5, 9]→ Output:"9534330" - Tricky cases:
[3, 30]→"330", not"303"— sorting numerically or lexicographically both give the wrong answer here. And[0, 0]→"0", not"00": the all-zeros input must be collapsed.
asked …