Largest Number

MediumStringMathSorting

Description

Given a list of non-negative integers nums, arrange them such that they form the largest number and return it as a string.

Examples

Input:nums = [10,2]
Output:"210"
Explanation:

Compare by concatenation: '210' > '102', so [2,10] arranged as '2'+'10' = '210' is larger than '10'+'2' = '102'.

Input:nums = [0,0,0]
Output:"0"
Explanation:

When every number is 0, the correct result is "0".

Input:nums = [432,43]
Output:"43432"
Explanation:

To determine the order, comparing concatenations: "43243" vs "43432". Since 43432 > 43243, placing 43 before 432. This shows how to handle cases where one number is a prefix of another.

Constraints

  • 1 ≤ nums.length ≤ 100
  • 0 ≤ nums[i] ≤ 10⁹

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!