Arrange Nonnegative Integers to Form the Largest Number
Company: LinkedIn
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Quick Answer: Arrange nonnegative integers so their decimal strings form the largest possible concatenation. The prompt requires every value exactly once, returns a string for unbounded result length, defines the all-zero case, and includes order-sensitive examples.
Constraints
- 1 <= nums.length <= 100,000
- 0 <= nums[i] <= 10^9
- Every input element must be used exactly once.
Examples
Input: ([10, 2],)
Expected Output: '210'
Explanation: Placing 2 before 10 produces the larger concatenation.
Input: ([3, 30, 34, 5, 9],)
Expected Output: '9534330'
Explanation: The source example needs concatenation order rather than ordinary numeric order.
Hints
- For two decimal strings a and b, compare a+b with b+a.
- Handle the all-zero input with the required canonical output.